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 <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi 2023-03-02 12:53:29 +08:00 committed by Alin Jerpelea
parent b01b93cb54
commit dfc70b1ddb
3 changed files with 18 additions and 3 deletions

View File

@ -111,6 +111,7 @@ void lib_stream_release(FAR struct task_group_s *group);
/* Functions contained in lib_getstreams.c **********************************/ /* Functions contained in lib_getstreams.c **********************************/
FAR struct streamlist *lib_get_streams(void); FAR struct streamlist *lib_get_streams(void);
FAR struct file_struct *lib_get_stream(int fd);
#endif /* CONFIG_FILE_STREAM */ #endif /* CONFIG_FILE_STREAM */
/* Functions defined in lib_srand.c *****************************************/ /* Functions defined in lib_srand.c *****************************************/

View File

@ -63,9 +63,9 @@
/* The first three _iob entries are reserved for standard I/O */ /* The first three _iob entries are reserved for standard I/O */
#define stdin (&lib_get_streams()->sl_std[0]) #define stdin lib_get_stream(0)
#define stdout (&lib_get_streams()->sl_std[1]) #define stdout lib_get_stream(1)
#define stderr (&lib_get_streams()->sl_std[2]) #define stderr lib_get_stream(2)
/* Path to the directory where temporary files can be created */ /* Path to the directory where temporary files can be created */

View File

@ -57,4 +57,18 @@ FAR struct streamlist *lib_get_streams(void)
return &info->ta_streamlist; 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 */ #endif /* CONFIG_FILE_STREAM */