This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push: new dfc70b1ddb libc/stdio: Implement lib_get_stream dfc70b1ddb is described below commit dfc70b1ddb25d776ad8ed7660ffee416fefd6602 Author: Huang Qi <huang...@xiaomi.com> AuthorDate: Thu Mar 2 12:53:29 2023 +0800 libc/stdio: Implement lib_get_stream Use lib_get_stream() to fetch stdin/stdout/stderr, since is more easy to works with other language by function call than export native C structure memory layout. Signed-off-by: Huang Qi <huang...@xiaomi.com> --- include/nuttx/lib/lib.h | 1 + include/stdio.h | 6 +++--- libs/libc/stdio/lib_libgetstreams.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/nuttx/lib/lib.h b/include/nuttx/lib/lib.h index df30581f87..df71eb988e 100644 --- a/include/nuttx/lib/lib.h +++ b/include/nuttx/lib/lib.h @@ -111,6 +111,7 @@ void lib_stream_release(FAR struct task_group_s *group); /* Functions contained in lib_getstreams.c **********************************/ FAR struct streamlist *lib_get_streams(void); +FAR struct file_struct *lib_get_stream(int fd); #endif /* CONFIG_FILE_STREAM */ /* Functions defined in lib_srand.c *****************************************/ diff --git a/include/stdio.h b/include/stdio.h index ebcfe1b430..854f8ce043 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -63,9 +63,9 @@ /* The first three _iob entries are reserved for standard I/O */ -#define stdin (&lib_get_streams()->sl_std[0]) -#define stdout (&lib_get_streams()->sl_std[1]) -#define stderr (&lib_get_streams()->sl_std[2]) +#define stdin lib_get_stream(0) +#define stdout lib_get_stream(1) +#define stderr lib_get_stream(2) /* Path to the directory where temporary files can be created */ diff --git a/libs/libc/stdio/lib_libgetstreams.c b/libs/libc/stdio/lib_libgetstreams.c index 3c31ecae1a..cb3025f60a 100644 --- a/libs/libc/stdio/lib_libgetstreams.c +++ b/libs/libc/stdio/lib_libgetstreams.c @@ -57,4 +57,18 @@ FAR struct streamlist *lib_get_streams(void) return &info->ta_streamlist; } +/**************************************************************************** + * Name: lib_get_stream + * + * Description: + * Return a pointer to the file stream for this thread and given fd。 + * Note: only reserved fd number 0/1/2 is valid. + * + ****************************************************************************/ + +FAR struct file_struct *lib_get_stream(int fd) +{ + return &lib_get_streams()->sl_std[fd]; +} + #endif /* CONFIG_FILE_STREAM */