nsh: Decouple with CONFIG_FILE_STREAM

Replace all fwrite/fread/fgets/... to write/read/...

Before:
```
       text    data     bss     dec     hex filename
 109827     601    6608  117036   1c92c nuttx/nuttx
```
    After:
```
       text    data     bss     dec     hex filename
108053     601    6608  115262   1c23e nuttx/nuttx
```
    After with CONFIG_FILE_STREAM disabled:
```
       text    data     bss     dec     hex filename
 105667     601    6608  112876   1b8ec nuttx/nuttx
```

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
Huang Qi
2023-02-10 17:50:46 +08:00
committed by Xiang Xiao
parent 6a686ba93d
commit 95f32fd018
16 changed files with 99 additions and 798 deletions

View File

@@ -60,10 +60,6 @@ static int nsh_clone_console(FAR struct console_stdio_s *pstate)
return -ENODEV;
}
/* Flush stderr: we only flush stderr if we opened the alternative one */
fflush(stderr);
/* Associate the new opened file descriptor to stderr */
dup2(fd, 2);
@@ -83,10 +79,6 @@ static int nsh_clone_console(FAR struct console_stdio_s *pstate)
return -ENODEV;
}
/* Flush stdout: we only flush stdout if we opened the alternative one */
fflush(stdout);
/* Associate the new opened file descriptor to stdout */
dup2(fd, 1);
@@ -100,23 +92,11 @@ static int nsh_clone_console(FAR struct console_stdio_s *pstate)
/* Setup the stderr */
pstate->cn_errfd = 2;
pstate->cn_errstream = fdopen(pstate->cn_errfd, "a");
if (!pstate->cn_errstream)
{
free(pstate);
return -EIO;
}
ERRFD(pstate) = 2;
/* Setup the stdout */
pstate->cn_outfd = 1;
pstate->cn_outstream = fdopen(pstate->cn_outfd, "a");
if (!pstate->cn_outstream)
{
free(pstate);
return -EIO;
}
OUTFD(pstate) = 1;
return OK;
}
@@ -196,15 +176,6 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s *pstate,
pstate->cn_confd = 0;
/* Create a standard C stream on the console device */
pstate->cn_constream = fdopen(pstate->cn_confd, "r+");
if (!pstate->cn_constream)
{
free(pstate);
return -EIO;
}
/* Close the input device that we just opened */
close(fd);