Browse Source

Merge pull request #2100 from gbcwbz/vi

Fix stdio fd error when POSIX api is used
Bernard Xiong 6 years ago
parent
commit
56f1a8af4f
2 changed files with 13 additions and 1 deletions
  1. 9 0
      components/dfs/src/dfs.c
  2. 4 1
      components/libc/compilers/armlibc/stubs.c

+ 9 - 0
components/dfs/src/dfs.c

@@ -18,6 +18,10 @@
 #include <lwp.h>
 #endif
 
+#ifdef RT_USING_DFS_DEVFS
+#include <libc.h>
+#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)

+ 4 - 1
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)