libfread: Fixed error flag when reading a write-only file.

This commit is contained in:
Fotis Panagiotopoulos 2022-10-18 11:39:52 +03:00 committed by Xiang Xiao
parent 6b31918b42
commit 10d6de46e6

View File

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