diff --git a/libs/libc/stdio/lib_libfread.c b/libs/libc/stdio/lib_libfread.c index 98a4704160..a689ba79c0 100644 --- a/libs/libc/stdio/lib_libfread.c +++ b/libs/libc/stdio/lib_libfread.c @@ -55,11 +55,17 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) /* Make sure that reading from this stream is allowed */ - if (!stream || (stream->fs_oflags & O_RDOK) == 0) + if (!stream) { _NX_SETERRNO(EBADF); return ERROR; } + else if ((stream->fs_oflags & O_RDOK) == 0) + { + stream->fs_flags |= __FS_FLAG_ERROR; + _NX_SETERRNO(EBADF); + return ERROR; + } else { /* The stream must be stable until we complete the read */