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

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

commit a5ef6d57c1154746b1c6b5fbe9ca418571f8a65e
Author: Xiang Xiao <[email protected]>
AuthorDate: Sun Mar 26 11:56:12 2023 +0800

    system/cu: Remove the dependence on stdio FILE * function
    
    Signed-off-by: Xiang Xiao <[email protected]>
---
 system/cu/cu_main.c | 34 +++++++++++++++++-----------------
 1 file changed, 17 insertions(+), 17 deletions(-)

diff --git a/system/cu/cu_main.c b/system/cu/cu_main.c
index 2807411e6..986d31fa4 100644
--- a/system/cu/cu_main.c
+++ b/system/cu/cu_main.c
@@ -59,7 +59,7 @@
 #ifdef CONFIG_SYSTEM_CUTERM_DISABLE_ERROR_PRINT
 # define cu_error(...)
 #else
-# define cu_error(...) fprintf(stderr, __VA_ARGS__)
+# define cu_error(...) dprintf(STDERR_FILENO, __VA_ARGS__)
 #endif
 
 /****************************************************************************
@@ -110,8 +110,7 @@ static FAR void *cu_listener(FAR void *parameter)
           break;
         }
 
-      fputc(ch, stdout);
-      fflush(stdout);
+      write(STDOUT_FILENO, &ch, 1);
     }
 
   /* Won't get here */
@@ -288,7 +287,6 @@ int main(int argc, FAR char *argv[])
   int nocrlf = 0;
   int option;
   int ret;
-  int bcmd;
   int start_of_line = 1;
   int exitval = EXIT_FAILURE;
   bool badarg = false;
@@ -383,17 +381,17 @@ int main(int argc, FAR char *argv[])
    * right descriptor that is used to refer to tty
    */
 
-  if (isatty(fileno(stderr)))
+  if (isatty(STDERR_FILENO))
     {
-      cu->stdfd = fileno(stderr);
+      cu->stdfd = STDERR_FILENO;
     }
-  else if (isatty(fileno(stdout)))
+  else if (isatty(STDOUT_FILENO))
     {
-      cu->stdfd = fileno(stdout);
+      cu->stdfd = STDOUT_FILENO;
     }
-  else if (isatty(fileno(stdin)))
+  else if (isatty(STDIN_FILENO))
     {
-      cu->stdfd = fileno(stdin);
+      cu->stdfd = STDIN_FILENO;
     }
   else
     {
@@ -440,24 +438,26 @@ int main(int argc, FAR char *argv[])
   while (!cu->force_exit)
     {
       char ch;
-      int c = getc(stdin);
 
-      if (c < 0)
+      if (read(STDIN_FILENO, &ch, 1) <= 0)
         {
           continue;
         }
 
-      ch = c;
-
       if (start_of_line == 1 && ch == cu->escape)
         {
           /* We've seen and escape (~) character, echo it to local
            * terminal and read the next char from serial
            */
 
-          fputc(ch, stdout);
-          bcmd = getc(stdin);
-          if (bcmd == ch)
+          write(STDOUT_FILENO, &ch, 1);
+
+          if (read(STDIN_FILENO, &ch, 1) <= 0)
+            {
+              continue;
+            }
+
+          if (ch == cu->escape)
             {
               /* Escaping a tilde: handle like normal char */
 

Reply via email to