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 <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc 2023-09-22 13:37:51 +02:00 committed by Xiang Xiao
parent a3bbea86ff
commit 529c0f1fc9
2 changed files with 14 additions and 2 deletions

View File

@ -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

View File

@ -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