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; } }