diff options
Diffstat (limited to 'nuttx/fs')
-rw-r--r-- | nuttx/fs/fs_read.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/nuttx/fs/fs_read.c b/nuttx/fs/fs_read.c index 9f171a316..6deb674b1 100644 --- a/nuttx/fs/fs_read.c +++ b/nuttx/fs/fs_read.c @@ -52,14 +52,14 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes) { FAR struct filelist *list; - int ret = EBADF; + int ret = -EBADF; /* Get the thread-specific file list */ list = sched_getfiles(); if (!list) { - *get_errno_ptr() = EMFILE; + errno = EMFILE; return ERROR; } @@ -90,6 +90,17 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes) } } } + + /* If an error occurred, set errno and return -1 (ERROR) */ + + if (ret < 0) + { + errno = -ret; + return ERROR; + } + + /* Otherwise, return the number of bytes read */ + return ret; } |