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

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

commit 529c0f1fc947de2731efcbbad2e912598192eb80
Author: Michal Lenc <michall...@seznam.cz>
AuthorDate: Fri Sep 22 13:37:51 2023 +0200

    system: use fileno to get stream file descriptor
    
    There is a POSIX defined interface to get file descriptor from file_struct
    stream. Applications should use it and not access the structure directly.
    
    Signed-off-by: Michal Lenc <michall...@seznam.cz>
---
 system/cle/cle.c           | 8 +++++++-
 system/readline/readline.c | 8 +++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/system/cle/cle.c b/system/cle/cle.c
index 31e01396c..9a0c0119c 100644
--- a/system/cle/cle.c
+++ b/system/cle/cle.c
@@ -1123,6 +1123,12 @@ int cle_fd(FAR char *line, FAR const char *prompt, 
uint16_t linelen,
 int cle(FAR char *line, FAR const char *prompt, uint16_t linelen,
         FAR FILE *instream, FAR FILE *outstream)
 {
-  return cle_fd(line, prompt, linelen, instream->fs_fd, outstream->fs_fd);
+  int instream_fd;
+  int outstream_fd;
+
+  instream_fd  = fileno(instream);
+  outstream_fd = fileno(outstream);
+
+  return cle_fd(line, prompt, linelen, instream_fd, outstream_fd);
 }
 #endif
diff --git a/system/readline/readline.c b/system/readline/readline.c
index 8f263c2a0..cad9999e1 100644
--- a/system/readline/readline.c
+++ b/system/readline/readline.c
@@ -44,12 +44,18 @@
 #ifdef CONFIG_FILE_STREAM
 ssize_t readline(FAR char *buf, int buflen, FILE *instream, FILE *outstream)
 {
+  int instream_fd;
+  int outstream_fd;
+
   /* Sanity checks */
 
   DEBUGASSERT(instream && outstream);
 
   /* Let readline_fd do the work */
 
-  return readline_fd(buf, buflen, instream->fs_fd, outstream->fs_fd);
+  instream_fd  = fileno(instream);
+  outstream_fd = fileno(outstream);
+
+  return readline_fd(buf, buflen, instream_fd, outstream_fd);
 }
 #endif

Reply via email to