libs/libc/stdio: fix ungetc operation
Do not modify errno in case of failure
Return EOF if the value of c equals to EOF
@@ -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;
}
}
