You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/10/14 15:29:44 UTC
[incubator-nuttx] branch master updated: libs/libc/stdio: fix ungetc operation
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/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new ec4a615f6c libs/libc/stdio: fix ungetc operation
ec4a615f6c is described below
commit ec4a615f6cfaed50d20fc4176dc18254533f9f52
Author: Petro Karashchenko <pe...@gmail.com>
AuthorDate: Fri Oct 14 11:54:56 2022 +0200
libs/libc/stdio: fix ungetc operation
Do not modify errno in case of failure
Return EOF if the value of c equals to EOF
Signed-off-by: Petro Karashchenko <pe...@gmail.com>
---
libs/libc/stdio/lib_ungetc.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/libs/libc/stdio/lib_ungetc.c b/libs/libc/stdio/lib_ungetc.c
index bf4a5833cd..f5ebea1e39 100644
--- a/libs/libc/stdio/lib_ungetc.c
+++ b/libs/libc/stdio/lib_ungetc.c
@@ -43,11 +43,10 @@ int ungetc(int c, FAR FILE *stream)
int nungotten;
#endif
- /* Verify that a non-NULL stream was provided */
+ /* Verify that a non-NULL stream was provided and c is not EOF */
- if (!stream)
+ if (!stream || c == EOF)
{
- set_errno(EBADF);
return EOF;
}
@@ -55,7 +54,6 @@ int ungetc(int c, FAR FILE *stream)
if ((stream->fs_fd < 0) || ((stream->fs_oflags & O_RDOK) == 0))
{
- set_errno(EBADF);
return EOF;
}
@@ -70,7 +68,6 @@ int ungetc(int c, FAR FILE *stream)
else
#endif
{
- set_errno(ENOMEM);
return EOF;
}
}