libc/stdio: Preallocate the stdin, stdout and stderr

to handle the uninitialized stdin/stdout/stderr gracefully
report here:
https://github.com/apache/incubator-nuttx/issues/2203

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2020-11-09 13:32:59 +08:00
committed by David Sidrane
parent 1dad55d4be
commit 84b90e00f0
4 changed files with 69 additions and 54 deletions
+4
View File
@@ -469,6 +469,9 @@ struct file_struct
FAR unsigned char *fs_bufend; /* Pointer to 1 past end of buffer */
FAR unsigned char *fs_bufpos; /* Current position in buffer */
FAR unsigned char *fs_bufread; /* Pointer to 1 past last buffered read char. */
# if CONFIG_STDIO_BUFFER_SIZE > 0
unsigned char fs_buffer[CONFIG_STDIO_BUFFER_SIZE];
# endif
#endif
uint16_t fs_oflags; /* Open mode flags */
uint8_t fs_flags; /* Stream flags */
@@ -481,6 +484,7 @@ struct file_struct
struct streamlist
{
sem_t sl_sem; /* For thread safety */
struct file_struct sl_std[3];
FAR struct file_struct *sl_head;
FAR struct file_struct *sl_tail;
};
+3 -3
View File
@@ -78,9 +78,9 @@
/* The first three _iob entries are reserved for standard I/O */
#define stdin (nxsched_get_streams()->sl_head)
#define stdout (nxsched_get_streams()->sl_head->fs_next)
#define stderr (nxsched_get_streams()->sl_head->fs_next->fs_next)
#define stdin (&nxsched_get_streams()->sl_std[0])
#define stdout (&nxsched_get_streams()->sl_std[1])
#define stderr (&nxsched_get_streams()->sl_std[2])
/* Path to the directory where temporary files can be created */