From 0924d277f67258c7c264cab1287671bf04bea231 Mon Sep 17 00:00:00 2001 From: gbcwbz Date: Sun, 23 Dec 2018 19:14:14 +0800 Subject: [PATCH 1/2] [dfs] Fix stdio fd error when POSIX api is used POSIX api e.g. poll read write --- components/dfs/src/dfs.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index cf0b2b0ef9..12ae8e9d95 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -18,6 +18,10 @@ #include #endif +#ifdef RT_USING_DFS_DEVFS +#include +#endif + /* Global variables */ const struct dfs_filesystem_ops *filesystem_operation_table[DFS_FILESYSTEM_TYPES_MAX]; struct dfs_filesystem filesystem_table[DFS_FILESYSTEMS_MAX]; @@ -212,6 +216,11 @@ struct dfs_fd *fd_get(int fd) struct dfs_fd *d; struct dfs_fdtable *fdt; +#ifdef RT_USING_DFS_DEVFS + if ((0 <= fd) && (fd <= 2)) + fd = libc_stdio_get_console(); +#endif + fdt = dfs_fdtable_get(); fd = fd - DFS_FD_OFFSET; if (fd < 0 || fd >= fdt->maxfd) From 48848c2917c42a8826b3144211a62093c86f086b Mon Sep 17 00:00:00 2001 From: gbcwbz Date: Sun, 23 Dec 2018 19:15:20 +0800 Subject: [PATCH 2/2] [libc][armlibc] Fix getchar error after exit vi - _sys_istty() add stdio as tty - without this, after exit vi program getchar will return -1, I don't know why it works --- components/libc/compilers/armlibc/stubs.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/libc/compilers/armlibc/stubs.c b/components/libc/compilers/armlibc/stubs.c index 6e9f13d143..820daeff39 100644 --- a/components/libc/compilers/armlibc/stubs.c +++ b/components/libc/compilers/armlibc/stubs.c @@ -270,7 +270,10 @@ long _sys_flen(FILEHANDLE fh) int _sys_istty(FILEHANDLE fh) { - return 0; + if((STDIN <= fh) && (fh <= STDERR)) + return 1; + else + return 0; } int remove(const char *filename)