Allow changing write function of stdout (#304)

* Allow changing write function of stdout.

Required for stdout redirection.
Works on blocks, not chars - does _not_ use sdk_os_putc !
Should work even when linking with SPIFFS.
This commit is contained in:
otopetrik 2016-12-19 16:55:26 +01:00 committed by Ruslan V. Uss
parent 97268eff29
commit 8f5d49de81
3 changed files with 90 additions and 28 deletions

View file

@ -0,0 +1,45 @@
/*
* Part of esp-open-rtos
* Copyright (C) 2016 Oto Petrik <oto.petrik@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#ifndef _STDOUT_REDIRECT_H_
#define _STDOUT_REDIRECT_H_
#include <sys/reent.h>
#ifdef __cplusplus
extern "C"
{
#endif
typedef long _WriteFunction(struct _reent *r, int fd, const char *ptr, int len );
/** Set implementation of write syscall for stdout.
*
* Use this function to redirect stdout for further processing (save to file, send over network).
* It may be good idea to save result of `get_write_stdout()` beforehand and call
* it at the end of the supplied function.
*
* NOTE: use NULL to reset to default implementation.
*
* @param[in] f New code to handle stdout output
*
*/
void set_write_stdout(_WriteFunction *f);
/** Get current implementation of write syscall for stdout.
*
* Save returned value before calling `set_write_stdout`, it allows for chaining
* multiple independent handlers.
*
* @returns current stdout handler
*/
_WriteFunction *get_write_stdout();
#ifdef __cplusplus
}
#endif
#endif /* _STDOUT_REDIRECT_H_ */