From 181875f3bac79f79cedaa07bd539b3b7fba6a019 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 11 Oct 2017 12:13:41 -0600 Subject: [PATCH] fs/vfs: Add new internal OS interface nx_read(). nx_read() is functionally equivalent to read() except that it does not modify the errno variable and it is not a cancellation point. Changed all references to read() in the OS to nx_read(). --- binfmt/libelf/libelf_read.c | 47 ++++++----- binfmt/libnxflat/libnxflat_read.c | 15 ++-- binfmt/pcode.c | 16 ++-- configs/ea3131/src/lpc31_fillpage.c | 5 +- configs/ea3152/src/lpc31_fillpage.c | 5 +- configs/nucleo-l452re/src/stm32_adc.c | 11 +-- drivers/loop/losetup.c | 8 +- drivers/mtd/filemtd.c | 12 +-- drivers/wireless/cc3000/cc3000drv.c | 3 +- fs/mmap/fs_rammap.c | 28 ++----- fs/vfs/fs_read.c | 110 ++++++++++++++++---------- include/nuttx/fs/fs.h | 44 ++++++++++- libc/misc/lib_sendfile.c | 11 ++- libc/modlib/modlib_read.c | 5 +- libc/stdio/lib_libfread.c | 18 +++-- libc/stdio/lib_rawinstream.c | 8 +- libc/stdio/lib_rawsistream.c | 6 +- libc/time/lib_localtime.c | 11 ++- 18 files changed, 222 insertions(+), 141 deletions(-) diff --git a/binfmt/libelf/libelf_read.c b/binfmt/libelf/libelf_read.c index cdadf4444e..490ba1fdd9 100644 --- a/binfmt/libelf/libelf_read.c +++ b/binfmt/libelf/libelf_read.c @@ -47,6 +47,7 @@ #include #include +#include #include /**************************************************************************** @@ -134,31 +135,29 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer, /* Read the file data at offset into the user buffer */ - nbytes = read(loadinfo->filfd, buffer, readsize); - if (nbytes < 0) - { - int errval = errno; + nbytes = nx_read(loadinfo->filfd, buffer, readsize); + if (nbytes < 0) + { + /* EINTR just means that we received a signal */ - /* EINTR just means that we received a signal */ - - if (errval != EINTR) - { - berr("Read from offset %lu failed: %d\n", - (unsigned long)offset, errval); - return -errval; - } - } - else if (nbytes == 0) - { - berr("Unexpected end of file\n"); - return -ENODATA; - } - else - { - readsize -= nbytes; - buffer += nbytes; - offset += nbytes; - } + if (nbytes != -EINTR) + { + berr("Read from offset %lu failed: %d\n", + (unsigned long)offset, (int)nbytes); + return nbytes; + } + } + else if (nbytes == 0) + { + berr("Unexpected end of file\n"); + return -ENODATA; + } + else + { + readsize -= nbytes; + buffer += nbytes; + offset += nbytes; + } } elf_dumpreaddata(buffer, readsize); diff --git a/binfmt/libnxflat/libnxflat_read.c b/binfmt/libnxflat/libnxflat_read.c index 678dd6d671..720f725679 100644 --- a/binfmt/libnxflat/libnxflat_read.c +++ b/binfmt/libnxflat/libnxflat_read.c @@ -48,6 +48,8 @@ #include #include + +#include #include /**************************************************************************** @@ -106,7 +108,8 @@ static inline void nxflat_dumpreaddata(FAR char *buffer, int buflen) * ****************************************************************************/ -int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, int offset) +int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, + int readsize, int offset) { ssize_t nbytes; /* Number of bytes read */ off_t rpos; /* Position returned by lseek */ @@ -135,14 +138,14 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer, int readsize, /* Read the file data at offset into the user buffer */ - nbytes = read(loadinfo->filfd, bufptr, bytesleft); + nbytes = nx_read(loadinfo->filfd, bufptr, bytesleft); if (nbytes < 0) { - int errval = errno; - if (errval != EINTR) + if (nbytes != -EINTR) { - berr("Read from offset %d failed: %d\n", offset, errval); - return -errval; + berr("Read from offset %d failed: %d\n", + offset, (int)nbytes); + return nbytes; } } else if (nbytes == 0) diff --git a/binfmt/pcode.c b/binfmt/pcode.c index 17b1383bbe..7e38c14e9b 100644 --- a/binfmt/pcode.c +++ b/binfmt/pcode.c @@ -49,6 +49,7 @@ #include #include +#include #include #include #include @@ -404,20 +405,17 @@ static int pcode_load(struct binary_s *binp) { /* Read the next GULP */ - nread = read(fd, ptr, remaining); + nread = nx_read(fd, ptr, remaining); if (nread < 0) { - /* If errno is EINTR, then this is not an error; the read() was - * simply interrupted by a signal. + /* If the failure is EINTR, then this is not an error; the + * nx_read() was simply interrupted by a signal. */ - int errval = get_errno(); - DEBUGASSERT(errval > 0); - - if (errval != EINTR) + if (nread != -EINTR) { - berr("ERROR: read failed: %d\n", errval); - ret = -errval; + berr("ERROR: read failed: %d\n", (int)nread); + ret = nread; goto errout_with_fd; } diff --git a/configs/ea3131/src/lpc31_fillpage.c b/configs/ea3131/src/lpc31_fillpage.c index 5683472158..89b0e094a2 100644 --- a/configs/ea3131/src/lpc31_fillpage.c +++ b/configs/ea3131/src/lpc31_fillpage.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/ea3131/src/lpc31_fillpage.c * - * Copyright (C) 2010, 2012-2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2012-2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,6 +52,7 @@ # include # include # include +# include # ifdef CONFIG_EA3131_PAGING_SDSLOT # include # include @@ -439,7 +440,7 @@ int up_fillpage(FAR struct tcb_s *tcb, FAR void *vpage) /* And read the page data from that offset */ - nbytes = read(g_pgsrc.fd, vpage, PAGESIZE); + nbytes = nx_read(g_pgsrc.fd, vpage, PAGESIZE); DEBUGASSERT(nbytes == PAGESIZE); return OK; diff --git a/configs/ea3152/src/lpc31_fillpage.c b/configs/ea3152/src/lpc31_fillpage.c index 51ad18749e..629b50c8de 100644 --- a/configs/ea3152/src/lpc31_fillpage.c +++ b/configs/ea3152/src/lpc31_fillpage.c @@ -1,7 +1,7 @@ /**************************************************************************** * configs/ea3152/src/lpc31_fillpage.c * - * Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved. + * Copyright (C) 2011, 2013, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -52,6 +52,7 @@ # include # include # include +# include # ifdef CONFIG_EA3152_PAGING_SDSLOT # include # include @@ -439,7 +440,7 @@ int up_fillpage(FAR struct tcb_s *tcb, FAR void *vpage) /* And read the page data from that offset */ - nbytes = read(g_pgsrc.fd, vpage, PAGESIZE); + nbytes = nx_read(g_pgsrc.fd, vpage, PAGESIZE); DEBUGASSERT(nbytes == PAGESIZE); return OK; diff --git a/configs/nucleo-l452re/src/stm32_adc.c b/configs/nucleo-l452re/src/stm32_adc.c index 34ebb25e93..b12471e49b 100644 --- a/configs/nucleo-l452re/src/stm32_adc.c +++ b/configs/nucleo-l452re/src/stm32_adc.c @@ -47,9 +47,11 @@ #include #include +#include #include #include #include + #include "stm32l4_gpio.h" #include "stm32l4_adc.h" #include "nucleo-l452re.h" @@ -183,14 +185,13 @@ int stm32l4_adc_measure_voltages(uint32_t *vrefint, uint32_t *vbat, uint32_t *ve goto out_close; } - nbytes = read(fd, sample, sizeof(sample)); + nbytes = nx_read(fd, sample, sizeof(sample)); if (nbytes < 0) { - errval = errno; - ret = -errval; - if (errval != EINTR) + if (nbytes != -EINTR) { - aerr("ERROR: read failed: %d\n", errval); + aerr("ERROR: nx_read() failed: %d\n", nbytes); + ret = (int)nbytes; goto out_close; } diff --git a/drivers/loop/losetup.c b/drivers/loop/losetup.c index 55b61f455e..e62c786041 100644 --- a/drivers/loop/losetup.c +++ b/drivers/loop/losetup.c @@ -259,11 +259,11 @@ static ssize_t loop_read(FAR struct inode *inode, FAR unsigned char *buffer, do { - nbytesread = read(dev->fd, buffer, nsectors * dev->sectsize); - if (nbytesread < 0 && get_errno() != EINTR) + nbytesread = nx_read(dev->fd, buffer, nsectors * dev->sectsize); + if (nbytesread < 0 && nbytesread != -EINTR) { - _err("ERROR: Read failed: %d\n", get_errno()); - return -get_errno(); + _err("ERROR: Read failed: %d\n", nbytesread); + return (int)nbytesread; } } while (nbytesread < 0); diff --git a/drivers/mtd/filemtd.c b/drivers/mtd/filemtd.c index c68a49c326..865adfc295 100644 --- a/drivers/mtd/filemtd.c +++ b/drivers/mtd/filemtd.c @@ -162,8 +162,8 @@ static ssize_t filemtd_write(FAR struct file_dev_s *priv, size_t offset, /* Read more data from the file */ lseek(priv->fd, seekpos, SEEK_SET); - buflen = read(priv->fd, buf, sizeof(buf)); - pout = (FAR uint8_t *) buf; + buflen = nx_read(priv->fd, buf, sizeof(buf)); + pout = (FAR uint8_t *) buf; } /* Get the source and destination values */ @@ -231,9 +231,9 @@ static ssize_t filemtd_read(FAR struct file_dev_s *priv, { /* Set the starting location in the file */ - lseek(priv->fd, priv->offset + offsetbytes, SEEK_SET); + (void)lseek(priv->fd, priv->offset + offsetbytes, SEEK_SET); - return read(priv->fd, buffer, nbytes); + return nx_read(priv->fd, buffer, nbytes); } /**************************************************************************** @@ -325,7 +325,7 @@ static ssize_t filemtd_bread(FAR struct mtd_dev_s *dev, off_t startblock, /* Then read the data from the file */ - filemtd_read(priv, buf, offset, nbytes); + (void)filemtd_read(priv, buf, offset, nbytes); return nblocks; } @@ -387,7 +387,7 @@ static ssize_t filemtd_byteread(FAR struct mtd_dev_s *dev, off_t offset, return 0; } - filemtd_read(priv, buf, offset, nbytes); + (void)filemtd_read(priv, buf, offset, nbytes); return nbytes; } diff --git a/drivers/wireless/cc3000/cc3000drv.c b/drivers/wireless/cc3000/cc3000drv.c index 99d5136f96..acd9ae8528 100644 --- a/drivers/wireless/cc3000/cc3000drv.c +++ b/drivers/wireless/cc3000/cc3000drv.c @@ -55,6 +55,7 @@ #include "cc3000drv.h" #include +#include #include #include @@ -144,7 +145,7 @@ long cc3000_write(uint8_t *pUserBuffer, uint16_t usLength) long cc3000_read(uint8_t *pUserBuffer, uint16_t usLength) { DEBUGASSERT(spiconf.cc3000fd >= 0); - return read(spiconf.cc3000fd, pUserBuffer, usLength); + return nx_read(spiconf.cc3000fd, pUserBuffer, usLength); } /**************************************************************************** diff --git a/fs/mmap/fs_rammap.c b/fs/mmap/fs_rammap.c index 3f8d992489..fc8b25fb05 100644 --- a/fs/mmap/fs_rammap.c +++ b/fs/mmap/fs_rammap.c @@ -47,6 +47,7 @@ #include #include +#include #include #include "inode/inode.h" @@ -174,30 +175,23 @@ FAR void *rammap(int fd, size_t length, off_t offset) rdbuffer = map->addr; while (length > 0) { - nread = read(fd, rdbuffer, length); + nread = nx_read(fd, rdbuffer, length); if (nread < 0) { /* Handle the special case where the read was interrupted by a * signal. */ - errcode = get_errno(); - if (errcode != EINTR) + if (nread != -EINTR) { - /* All other read errors are bad. errno is already set. - * (but maybe should be forced to EINVAL?). NOTE that if - * FS DEBUG is enabled, then the following ferr() macro will - * destroy the errno value. - */ + /* All other read errors are bad. */ ferr("ERROR: Read failed: offset=%d errno=%d\n", - (int)offset, errcode); -#ifdef CONFIG_DEBUG_FS + (int)offset, (int)nread); + + errcode = (int)-ret; goto errout_with_region; -#else - goto errout_with_errno; -#endif - } + } } /* Check for end of file. */ @@ -239,12 +233,6 @@ errout_with_region: errout: set_errno(errcode); return MAP_FAILED; - -#ifndef CONFIG_DEBUG_FS -errout_with_errno: - kumm_free(alloc); - return MAP_FAILED; -#endif } #endif /* CONFIG_FS_RAMMAP */ diff --git a/fs/vfs/fs_read.c b/fs/vfs/fs_read.c index 23b2ef9707..8b0c96d6ae 100644 --- a/fs/vfs/fs_read.c +++ b/fs/vfs/fs_read.c @@ -60,16 +60,22 @@ * Name: file_read * * Description: - * This is the internal implementation of read(). + * file_read() is an interanl OS interface. It is functionally similar to + * the standard read() interface except: * - * Parameters: - * file File structure instance - * buf User-provided to save the data - * nbytes The maximum size of the user-provided buffer + * - It does not modify the errno variable, + * - It is not a cancellation point, + * - It does not handle socket descriptors, and + * - It accepts a file structure instance instead of file descriptor. * - * Return: + * Input Parameters: + * filep - File structure instance + * buf - User-provided to save the data + * nbytes - The maximum size of the user-provided buffer + * + * Returned Value: * The positive non-zero number of bytes read on success, 0 on if an - * end-of-file condition, or -1 on failure with errno set appropriately. + * end-of-file condition, or a negated errno value on any failure. * ****************************************************************************/ @@ -110,30 +116,30 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes) } /**************************************************************************** - * Name: read + * Name: nx_read * * Description: - * The standard, POSIX read interface. + * nx_read() is an interanl OS interface. It is functionally similar to + * the standard read() interface except: * - * Parameters: - * file File structure instance - * buf User-provided to save the data - * nbytes The maximum size of the user-provided buffer + * - It does not modify the errno variable, and + * - It is not a cancellation point. * - * Return: + * Input Parameters: + * fd - File descriptor to read from + * buf - User-provided to save the data + * nbytes - The maximum size of the user-provided buffer + * + * Returned Value: * The positive non-zero number of bytes read on success, 0 on if an - * end-of-file condition, or -1 on failure with errno set appropriately. + * end-of-file condition, or a negated errno value on any failure. * ****************************************************************************/ -ssize_t read(int fd, FAR void *buf, size_t nbytes) +ssize_t nx_read(int fd, FAR void *buf, size_t nbytes) { ssize_t ret; - /* read() is a cancellation point */ - - (void)enter_cancellation_point(); - /* Did we get a valid file descriptor? */ #if CONFIG_NFILE_DESCRIPTORS > 0 @@ -142,20 +148,14 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes) { #if defined(CONFIG_NET) && CONFIG_NSOCKET_DESCRIPTORS > 0 /* No.. If networking is enabled, read() is the same as recv() with - * the flags parameter set to zero. Note that recv() sets - * the errno variable. + * the flags parameter set to zero. */ - ret = nx_recv(fd, buf, nbytes, 0); - if (ret < 0) - { - goto errout; - } + return nx_recv(fd, buf, nbytes, 0); #else /* No networking... it is a bad descriptor in any event */ - ret = -EBADF; - goto errout; + return -EBADF; #endif } @@ -172,24 +172,54 @@ ssize_t read(int fd, FAR void *buf, size_t nbytes) ret = (ssize_t)fs_getfilep(fd, &filep); if (ret < 0) { - goto errout; + return ret; } /* Then let file_read do all of the work. */ - ret = file_read(filep, buf, nbytes); - if (ret < 0) - { - goto errout; - } + return file_read(filep, buf, nbytes); } +#else + /* I don't think we can get here */ + + return -ENOSYS; #endif +} + +/**************************************************************************** + * Name: read + * + * Description: + * The standard, POSIX read interface. + * + * Input Parameters: + * fd - File descriptor to read from + * buf - User-provided to save the data + * nbytes - The maximum size of the user-provided buffer + * + * Returned Value: + * The positive non-zero number of bytes read on success, 0 on if an + * end-of-file condition, or -1 on failure with errno set appropriately. + * + ****************************************************************************/ + +ssize_t read(int fd, FAR void *buf, size_t nbytes) +{ + ssize_t ret; + + /* read() is a cancellation point */ + + (void)enter_cancellation_point(); + + /* Let nx_read() do the real work */ + + ret = nx_read(fd, buf, nbytes); + if (ret < 0) + { + set_errno(-ret); + ret = ERROR; + } leave_cancellation_point(); return ret; - -errout: - set_errno((int)-ret); - leave_cancellation_point(); - return (ssize_t)ERROR; } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 79b6c5706c..8f2a1fd889 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -83,11 +83,13 @@ */ #if defined(CONFIG_BUILD_FLAT) || defined(__KERNEL__) +# define _NX_READ(f,b,s) nx_read(f,b,s) # define _NX_WRITE(f,b,s) nx_write(f,b,s) # define _NX_GETERRNO(r) (-(r)) # define _NX_SETERRNO(r) set_errno(-(r)) # define _NX_GETERRVAL(r) (r) #else +# define _NX_READ(f,b,s) read(f,b,s) # define _NX_WRITE(f,b,s) write(f,b,s) # define _NX_GETERRNO(r) errno # define _NX_SETERRNO(r) @@ -913,9 +915,22 @@ int fs_getfilep(int fd, FAR struct file **filep); * Name: file_read * * Description: - * Equivalent to the standard read() function except that is accepts a - * struct file instance instead of a file descriptor. Currently used - * only by net_sendfile() and aio_read(); + * file_read() is an interanl OS interface. It is functionally similar to + * the standard read() interface except: + * + * - It does not modify the errno variable, + * - It is not a cancellation point, + * - It does not handle socket descriptors, and + * - It accepts a file structure instance instead of file descriptor. + * + * Input Parameters: + * filep - File structure instance + * buf - User-provided to save the data + * nbytes - The maximum size of the user-provided buffer + * + * Returned Value: + * The positive non-zero number of bytes read on success, 0 on if an + * end-of-file condition, or a negated errno value on any failure. * ****************************************************************************/ @@ -923,6 +938,29 @@ int fs_getfilep(int fd, FAR struct file **filep); ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes); #endif +/**************************************************************************** + * Name: nx_read + * + * Description: + * nx_read() is an interanl OS interface. It is functionally similar to + * the standard read() interface except: + * + * - It does not modify the errno variable, and + * - It is not a cancellation point. + * + * Input Parameters: + * fd - File descriptor to read from + * buf - User-provided to save the data + * nbytes - The maximum size of the user-provided buffer + * + * Returned Value: + * The positive non-zero number of bytes read on success, 0 on if an + * end-of-file condition, or a negated errno value on any failure. + * + ****************************************************************************/ + +ssize_t nx_read(int fd, FAR void *buf, size_t nbytes); + /**************************************************************************** * Name: file_write * diff --git a/libc/misc/lib_sendfile.c b/libc/misc/lib_sendfile.c index 0e3bd7bacd..6cc7b4c49e 100644 --- a/libc/misc/lib_sendfile.c +++ b/libc/misc/lib_sendfile.c @@ -152,7 +152,7 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) { /* Read a buffer of data from the infd */ - nbytesread = read(infd, iobuffer, CONFIG_LIB_SENDFILE_BUFSIZE); + nbytesread = _NX_READ(infd, iobuffer, CONFIG_LIB_SENDFILE_BUFSIZE); /* Check for end of file */ @@ -174,14 +174,17 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) else if (nbytesread < 0) { + int errcode = _NX_GETERRNO(nbytesread); + /* EINTR is not an error (but will still stop the copy) */ #ifndef CONFIG_DISABLE_SIGNALS - if (errno != EINTR || ntransferred == 0) + if (errcode != EINTR || ntransferred == 0) #endif { /* Read error. Break out and return the error condition. */ + _NX_SETERRNO(nbytesread); ntransferred = ERROR; endxfr = true; break; @@ -241,7 +244,9 @@ ssize_t sendfile(int outfd, int infd, off_t *offset, size_t count) if (errcode != EINTR || ntransferred == 0) #endif { - /* Write error. Break out and return the error condition */ + /* Write error. Break out and return the error + * condition. + */ _NX_SETERRNO(nbyteswritten); ntransferred = ERROR; diff --git a/libc/modlib/modlib_read.c b/libc/modlib/modlib_read.c index 84ae5fb3b6..169d581429 100644 --- a/libc/modlib/modlib_read.c +++ b/libc/modlib/modlib_read.c @@ -48,6 +48,7 @@ #include #include +#include #include /**************************************************************************** @@ -128,10 +129,10 @@ int modlib_read(FAR struct mod_loadinfo_s *loadinfo, FAR uint8_t *buffer, /* Read the file data at offset into the user buffer */ - nbytes = read(loadinfo->filfd, buffer, readsize); + nbytes = _NX_READ(loadinfo->filfd, buffer, readsize); if (nbytes < 0) { - int errval = errno; + int errval = _NX_GETERRNO(nbytes); /* EINTR just means that we received a signal */ diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index d41639d800..373694e8eb 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -46,6 +46,8 @@ #include #include +#include + #include "libc.h" /**************************************************************************** @@ -154,13 +156,12 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) if (count > buffer_available) { - bytes_read = read(stream->fs_fd, dest, count); + bytes_read = _NX_READ(stream->fs_fd, dest, count); if (bytes_read < 0) { - /* An error occurred on the read. The error code is - * in the 'errno' variable. - */ + /* An error occurred on the read. */ + _NX_SETERRNO(bytes_read); goto errout_with_errno; } else if (bytes_read == 0) @@ -202,14 +203,16 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) * into the buffer. */ - bytes_read = read(stream->fs_fd, stream->fs_bufread, - buffer_available); + bytes_read = _NX_READ(stream->fs_fd, + stream->fs_bufread, + buffer_available); if (bytes_read < 0) { /* An error occurred on the read. The error code is * in the 'errno' variable. */ + _NX_SETERRNO(bytes_read); goto errout_with_errno; } else if (bytes_read == 0) @@ -238,13 +241,14 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) while (count > 0) { - bytes_read = read(stream->fs_fd, dest, count); + bytes_read = _NX_READ(stream->fs_fd, dest, count); if (bytes_read < 0) { /* An error occurred on the read. The error code is * in the 'errno' variable. */ + _NX_SETERRNO(bytes_read); goto errout_with_errno; } else if (bytes_read == 0) diff --git a/libc/stdio/lib_rawinstream.c b/libc/stdio/lib_rawinstream.c index 913a413bff..e37f3630fd 100644 --- a/libc/stdio/lib_rawinstream.c +++ b/libc/stdio/lib_rawinstream.c @@ -1,7 +1,7 @@ /**************************************************************************** * libc/stdio/lib_rawsistream.c * - * Copyright (C) 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -37,10 +37,14 @@ * Included Files ****************************************************************************/ +#include + #include #include #include +#include + #include "libc.h" /**************************************************************************** @@ -61,7 +65,7 @@ static int rawsistream_getc(FAR struct lib_sistream_s *this) /* Attempt to read one character */ - nwritten = read(rthis->fd, &ch, 1); + nwritten = _NX_READ(rthis->fd, &ch, 1); if (nwritten == 1) { this->nget++; diff --git a/libc/stdio/lib_rawsistream.c b/libc/stdio/lib_rawsistream.c index d52fad1daf..d332728c07 100644 --- a/libc/stdio/lib_rawsistream.c +++ b/libc/stdio/lib_rawsistream.c @@ -37,10 +37,14 @@ * Included Files ****************************************************************************/ +#include + #include #include #include +#include + #include "libc.h" /**************************************************************************** @@ -61,7 +65,7 @@ static int rawinstream_getc(FAR struct lib_instream_s *this) /* Attempt to read one character */ - nwritten = read(rthis->fd, &ch, 1); + nwritten = _NX_READ(rthis->fd, &ch, 1); if (nwritten == 1) { this->nget++; diff --git a/libc/time/lib_localtime.c b/libc/time/lib_localtime.c index 24bec13194..ac5cd64f64 100644 --- a/libc/time/lib_localtime.c +++ b/libc/time/lib_localtime.c @@ -58,6 +58,8 @@ #include #include +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -545,10 +547,10 @@ static int tzload(FAR const char *name, sp->goback = sp->goahead = FALSE; - if (!name) + if (name == NULL) { name = TZDEFAULT; - if (!name) + if (name == NULL) { goto oops; } @@ -563,7 +565,8 @@ static int tzload(FAR const char *name, if (!doaccess) { p = TZDIR; - if (!p || sizeof lsp->fullname - 1 <= strlen(p) + strlen(name)) + if (p == NULL || + sizeof(lsp->fullname - 1) <= strlen(p) + strlen(name)) { goto oops; } @@ -593,7 +596,7 @@ static int tzload(FAR const char *name, goto oops; } - nread = read(fid, up->buf, sizeof up->buf); + nread = _NX_READ(fid, up->buf, sizeof up->buf); if (close(fid) < 0 || nread <= 0) { goto oops;