Skip to content

Commit

Permalink
system: use fileno to get stream file descriptor
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
michallenc authored and xiaoxiang781216 committed Oct 9, 2023
1 parent a3bbea8 commit 529c0f1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion system/cle/cle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 7 additions & 1 deletion system/readline/readline.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 529c0f1

Please sign in to comment.