This is an automated email from the ASF dual-hosted git repository.

ligd pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git

commit 359f66ad3701c8a53b6344fe49a2d8d01e9c7f97
Author: Xiang Xiao <xiaoxi...@xiaomi.com>
AuthorDate: Wed Feb 22 06:08:13 2023 +0800

    nshlib: Remove the remaining CONFIG_FILE_STREAM dependence
    
    continue the change from https://github.com/apache/nuttx-apps/pull/1559
    
    Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com>
---
 nshlib/nsh.h             | 12 ++----------
 nshlib/nsh_altconsole.c  |  4 +---
 nshlib/nsh_builtin.c     |  1 +
 nshlib/nsh_codeccmd.c    |  1 -
 nshlib/nsh_command.c     |  8 ++------
 nshlib/nsh_console.c     |  3 ++-
 nshlib/nsh_console.h     |  3 +--
 nshlib/nsh_consolemain.c |  3 ---
 nshlib/nsh_dbgcmds.c     |  1 +
 nshlib/nsh_ddcmd.c       |  2 ++
 nshlib/nsh_envcmds.c     |  1 -
 nshlib/nsh_fscmds.c      |  4 +---
 nshlib/nsh_fsutils.c     |  1 +
 nshlib/nsh_login.c       |  1 -
 nshlib/nsh_mmcmds.c      |  2 ++
 nshlib/nsh_modcmds.c     | 17 +++++++++--------
 nshlib/nsh_parse.c       |  5 ++++-
 nshlib/nsh_printf.c      |  1 -
 nshlib/nsh_script.c      |  6 +++---
 nshlib/nsh_system.c      |  1 -
 nshlib/nsh_telnetlogin.c |  1 -
 nshlib/nsh_usbconsole.c  |  6 ------
 nshlib/nsh_usbtrace.c    |  2 +-
 23 files changed, 33 insertions(+), 53 deletions(-)

diff --git a/nshlib/nsh.h b/nshlib/nsh.h
index 0ccd5992b..50205c8cc 100644
--- a/nshlib/nsh.h
+++ b/nshlib/nsh.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 
-#include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <unistd.h>
@@ -55,11 +54,6 @@
 #  endif
 #endif
 
-#ifndef CONFIG_FILE_STREAM
-#  undef CONFIG_NSH_FILE_APPS
-#  undef CONFIG_NSH_CMDPARMS
-#endif
-
 /* rmdir, mkdir, rm, and mv are only available if mountpoints are enabled
  * AND there is a writeable file system OR if these operations on the
  * pseudo-filesystem are not disabled.
@@ -988,11 +982,9 @@ int cmd_irqinfo(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv);
 #if !defined(CONFIG_NSH_DISABLE_READLINK) && defined(CONFIG_PSEUDOFS_SOFTLINKS)
   int cmd_readlink(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
 #endif
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-#  ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
   int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv);
-#  endif
-#endif /* CONFIG_FILE_STREAM && !CONFIG_NSH_DISABLESCRIPT */
+#endif
 
 #ifdef NSH_HAVE_DIROPTS
 #  ifndef CONFIG_NSH_DISABLE_MKDIR
diff --git a/nshlib/nsh_altconsole.c b/nshlib/nsh_altconsole.c
index 82f284fda..831725f4f 100644
--- a/nshlib/nsh_altconsole.c
+++ b/nshlib/nsh_altconsole.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -150,8 +149,7 @@ static int nsh_wait_inputdev(FAR struct console_stdio_s 
*pstate,
                * to open the keyboard device.
                */
 
-              puts(msg);
-              fflush(stdout);
+              write(STDOUT_FILENO, msg, strlen(msg));
               msg = NULL;
             }
 
diff --git a/nshlib/nsh_builtin.c b/nshlib/nsh_builtin.c
index 2e2c6d10f..583df84e3 100644
--- a/nshlib/nsh_builtin.c
+++ b/nshlib/nsh_builtin.c
@@ -31,6 +31,7 @@
 
 #include <stdbool.h>
 #include <errno.h>
+#include <sched.h>
 #include <string.h>
 
 #include <nuttx/lib/builtin.h>
diff --git a/nshlib/nsh_codeccmd.c b/nshlib/nsh_codeccmd.c
index 6eb4d026d..9b3efdcce 100644
--- a/nshlib/nsh_codeccmd.c
+++ b/nshlib/nsh_codeccmd.c
@@ -28,7 +28,6 @@
 #include <sys/stat.h>
 #include <stdint.h>
 #include <stdbool.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index efd3a366b..f3a7af0f5 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -87,10 +87,8 @@ static int  cmd_unrecognized(FAR struct nsh_vtbl_s *vtbl, 
int argc,
 
 static const struct cmdmap_s g_cmdmap[] =
 {
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-# ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
   { ".",        cmd_source,   2, 2, "<script-path>" },
-# endif
 #endif
 
 #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
@@ -515,10 +513,8 @@ static const struct cmdmap_s g_cmdmap[] =
   { "sleep",    cmd_sleep,    2, 2, "<sec>" },
 #endif
 
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-# ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
   { "source",   cmd_source,   2, 2, "<script-path>" },
-# endif
 #endif
 
 #if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_TEST)
diff --git a/nshlib/nsh_console.c b/nshlib/nsh_console.c
index 6494992b8..7d29749b1 100644
--- a/nshlib/nsh_console.c
+++ b/nshlib/nsh_console.c
@@ -24,6 +24,7 @@
 
 #include <nuttx/config.h>
 
+#include <sys/ioctl.h>
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -70,7 +71,7 @@ static void nsh_consoleredirect(FAR struct nsh_vtbl_s *vtbl, 
int fd,
 static void nsh_consoleundirect(FAR struct nsh_vtbl_s *vtbl,
                                 FAR uint8_t *save);
 static void nsh_consoleexit(FAR struct nsh_vtbl_s *vtbl,
-                            int exitstatus) anoreturn_function;
+                            int exitstatus) noreturn_function;
 
 /****************************************************************************
  * Private Functions
diff --git a/nshlib/nsh_console.h b/nshlib/nsh_console.h
index 4b0037b2c..cf5e75a89 100644
--- a/nshlib/nsh_console.h
+++ b/nshlib/nsh_console.h
@@ -29,7 +29,6 @@
 
 #include <sys/types.h>
 
-#include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
 #include <errno.h>
@@ -61,7 +60,7 @@
  * See struct serialsave_s in nsh_console.c
  */
 
-#define SAVE_SIZE (2 * sizeof(int) + 2 * sizeof(FILE*))
+#define SAVE_SIZE (2 * sizeof(int))
 
 /* Are we using the NuttX console for I/O?  Or some other character device? */
 
diff --git a/nshlib/nsh_consolemain.c b/nshlib/nsh_consolemain.c
index 29e138bf6..8590d0284 100644
--- a/nshlib/nsh_consolemain.c
+++ b/nshlib/nsh_consolemain.c
@@ -24,11 +24,8 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <assert.h>
 
-#include <sys/boardctl.h>
-
 #include "nsh.h"
 #include "nsh_console.h"
 
diff --git a/nshlib/nsh_dbgcmds.c b/nshlib/nsh_dbgcmds.c
index 85a6718ee..fc2b587a7 100644
--- a/nshlib/nsh_dbgcmds.c
+++ b/nshlib/nsh_dbgcmds.c
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
diff --git a/nshlib/nsh_ddcmd.c b/nshlib/nsh_ddcmd.c
index f9ac66901..dea661408 100644
--- a/nshlib/nsh_ddcmd.c
+++ b/nshlib/nsh_ddcmd.c
@@ -24,6 +24,8 @@
 
 #include <nuttx/config.h>
 
+#include <nuttx/clock.h>
+
 #include <sys/types.h>
 #include <sys/stat.h>
 
diff --git a/nshlib/nsh_envcmds.c b/nshlib/nsh_envcmds.c
index 5c0f347af..37b64f165 100644
--- a/nshlib/nsh_envcmds.c
+++ b/nshlib/nsh_envcmds.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/nshlib/nsh_fscmds.c b/nshlib/nsh_fscmds.c
index c13d829bd..d8c4fbe4d 100644
--- a/nshlib/nsh_fscmds.c
+++ b/nshlib/nsh_fscmds.c
@@ -1976,8 +1976,7 @@ int cmd_rmdir(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
  * Name: cmd_source
  ****************************************************************************/
 
-#if defined(CONFIG_FILE_STREAM) && !defined(CONFIG_NSH_DISABLESCRIPT)
-#ifndef CONFIG_NSH_DISABLE_SOURCE
+#if !defined(CONFIG_NSH_DISABLESCRIPT) && !defined(CONFIG_NSH_DISABLE_SOURCE)
 int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 {
   UNUSED(argc);
@@ -1985,7 +1984,6 @@ int cmd_source(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
   return nsh_script(vtbl, argv[0], argv[1], true);
 }
 #endif
-#endif
 
 /****************************************************************************
  * Name: cmd_cmp
diff --git a/nshlib/nsh_fsutils.c b/nshlib/nsh_fsutils.c
index 9d48c79bd..7a279b561 100644
--- a/nshlib/nsh_fsutils.c
+++ b/nshlib/nsh_fsutils.c
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
diff --git a/nshlib/nsh_login.c b/nshlib/nsh_login.c
index 19be58ae5..82857c406 100644
--- a/nshlib/nsh_login.c
+++ b/nshlib/nsh_login.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
diff --git a/nshlib/nsh_mmcmds.c b/nshlib/nsh_mmcmds.c
index 746054236..8f5953a99 100644
--- a/nshlib/nsh_mmcmds.c
+++ b/nshlib/nsh_mmcmds.c
@@ -24,6 +24,8 @@
 
 #include <nuttx/config.h>
 
+#include <string.h>
+
 #include "nsh.h"
 #include "nsh_console.h"
 
diff --git a/nshlib/nsh_modcmds.c b/nshlib/nsh_modcmds.c
index 549c384c8..6b935e877 100644
--- a/nshlib/nsh_modcmds.c
+++ b/nshlib/nsh_modcmds.c
@@ -24,10 +24,11 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
+#include <fcntl.h>
 #include <string.h>
 
 #include <nuttx/module.h>
+#include <system/readline.h>
 
 #include "nsh.h"
 #include "nsh_console.h"
@@ -103,18 +104,18 @@ int cmd_rmmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 #if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
 int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 {
-  UNUSED(argc);
+  int fd;
 
-  FILE *stream;
+  UNUSED(argc);
 
   /* Usage: lsmod */
 
   /* Open /proc/modules */
 
-  stream = fopen("/proc/modules", "r");
-  if (stream == NULL)
+  fd = open("/proc/modules", O_RDONLY);
+  if (fd < 0)
     {
-      nsh_error(vtbl, g_fmtcmdfailed, argv[0], "fopen", NSH_ERRNO);
+      nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
       return ERROR;
     }
 
@@ -126,7 +127,7 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
 
   /* Read each line from the procfs "file" */
 
-  while (fgets(vtbl->iobuffer, IOBUFFERSIZE, stream) != NULL)
+  while (readline_fd(vtbl->iobuffer, IOBUFFERSIZE, fd, -1) >= 0)
     {
       FAR char *modulename;
       FAR char *initializer;
@@ -175,7 +176,7 @@ int cmd_lsmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR 
char **argv)
                  datasize      ? datasize      : "");
     }
 
-  fclose(stream);
+  close(fd);
   return OK;
 }
 #endif /* CONFIG_FS_PROCFS && !CONFIG_FS_PROCFS_EXCLUDE_MODULE */
diff --git a/nshlib/nsh_parse.c b/nshlib/nsh_parse.c
index 169561e4c..0aabe5dbf 100644
--- a/nshlib/nsh_parse.c
+++ b/nshlib/nsh_parse.c
@@ -24,11 +24,14 @@
 
 #include <nuttx/config.h>
 
+#include <stdio.h>
 #include <stdlib.h>
 #include <fcntl.h>
 #include <string.h>
 #include <errno.h>
 #include <debug.h>
+#include <pthread.h>
+#include <sched.h>
 #include <unistd.h>
 
 #ifdef CONFIG_NSH_CMDPARMS
@@ -1958,7 +1961,7 @@ static int nsh_loop(FAR struct nsh_vtbl_s *vtbl, FAR char 
**ppcmd,
                           SEEK_SET);
               if (ret < 0)
                 {
-                  nsh_error(vtbl, g_fmtcmdfailed, "done", "fseek",
+                  nsh_error(vtbl, g_fmtcmdfailed, "done", "lseek",
                             NSH_ERRNO);
                 }
 
diff --git a/nshlib/nsh_printf.c b/nshlib/nsh_printf.c
index c57893c8c..bb088e764 100644
--- a/nshlib/nsh_printf.c
+++ b/nshlib/nsh_printf.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/nshlib/nsh_script.c b/nshlib/nsh_script.c
index 99e61a60b..9acf681f3 100644
--- a/nshlib/nsh_script.c
+++ b/nshlib/nsh_script.c
@@ -115,7 +115,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR 
char *cmd,
         {
           if (log)
             {
-              nsh_error(vtbl, g_fmtcmdfailed, cmd, "fopen", NSH_ERRNO);
+              nsh_error(vtbl, g_fmtcmdfailed, cmd, "open", NSH_ERRNO);
             }
 
           /* Free the allocated path */
@@ -138,7 +138,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR 
char *cmd,
           /* Get the current file position.  This is used to control
            * looping.  If a loop begins in the next line, then this file
            * offset will be needed to locate the top of the loop in the
-           * script file.  Note that ftell will return -1 on failure.
+           * script file.  Note that lseek will return -1 on failure.
            */
 
           vtbl->np.np_foffs = lseek(vtbl->np.np_fd, 0, SEEK_CUR);
@@ -146,7 +146,7 @@ int nsh_script(FAR struct nsh_vtbl_s *vtbl, FAR const FAR 
char *cmd,
 
           if (vtbl->np.np_foffs < 0 && log)
             {
-              nsh_error(vtbl, g_fmtcmdfailed, "loop", "ftell", NSH_ERRNO);
+              nsh_error(vtbl, g_fmtcmdfailed, "loop", "lseek", NSH_ERRNO);
             }
 #endif
 
diff --git a/nshlib/nsh_system.c b/nshlib/nsh_system.c
index 7603dfc94..26aaecbd2 100644
--- a/nshlib/nsh_system.c
+++ b/nshlib/nsh_system.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <assert.h>
diff --git a/nshlib/nsh_telnetlogin.c b/nshlib/nsh_telnetlogin.c
index 6592403b6..c2ec13a53 100644
--- a/nshlib/nsh_telnetlogin.c
+++ b/nshlib/nsh_telnetlogin.c
@@ -24,7 +24,6 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <unistd.h>
diff --git a/nshlib/nsh_usbconsole.c b/nshlib/nsh_usbconsole.c
index 04233a990..bc95c7d9a 100644
--- a/nshlib/nsh_usbconsole.c
+++ b/nshlib/nsh_usbconsole.c
@@ -26,7 +26,6 @@
 
 #include <sys/boardctl.h>
 
-#include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <fcntl.h>
@@ -62,11 +61,6 @@
 
 static void nsh_configstdio(int fd)
 {
-  /* Make sure the stdout, and stderr are flushed */
-
-  fflush(stdout);
-  fflush(stderr);
-
   /* Dup the fd to create standard fd 0-2 */
 
   dup2(fd, 0);
diff --git a/nshlib/nsh_usbtrace.c b/nshlib/nsh_usbtrace.c
index c00d2c90a..3faaae348 100644
--- a/nshlib/nsh_usbtrace.c
+++ b/nshlib/nsh_usbtrace.c
@@ -24,7 +24,7 @@
 
 #include <nuttx/config.h>
 
-#include <stdio.h>
+#include <stdarg.h>
 #include <debug.h>
 
 #include <nuttx/usb/usbdev_trace.h>

Reply via email to