This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit e74ee9208efa24dd571e2c76071497fdd2f9f033 Author: Marco Casaroli <[email protected]> AuthorDate: Mon Nov 2 10:45:15 2026 +0100 libs/libc/stdio: Set errno to EBADF in fread() on a write-only stream. fread() on a NULL stream or on a stream that is open only for writing returned an error but did not set errno. lib_fread_unlocked() used _NX_SETERRNO(EBADF), but _NX_SETERRNO() takes the return value of a failed call: in user space and in the flat build it does nothing, and in the kernel copy of libc it sets errno to -EBADF. Use set_errno(EBADF), as lib_fwrite_unlocked() does. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <[email protected]> --- libs/libc/stdio/lib_libfread_unlocked.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/libc/stdio/lib_libfread_unlocked.c b/libs/libc/stdio/lib_libfread_unlocked.c index 91c26f94a0b..205b1775a2e 100644 --- a/libs/libc/stdio/lib_libfread_unlocked.c +++ b/libs/libc/stdio/lib_libfread_unlocked.c @@ -61,13 +61,13 @@ ssize_t lib_fread_unlocked(FAR void *ptr, size_t count, FAR FILE *stream) if (!stream) { - _NX_SETERRNO(EBADF); + set_errno(EBADF); return ERROR; } else if ((stream->fs_oflags & O_ACCMODE) == O_WRONLY) { stream->fs_flags |= __FS_FLAG_ERROR; - _NX_SETERRNO(EBADF); + set_errno(EBADF); return ERROR; } else
