diff --git a/libc/stdio/lib_libfread.c b/libc/stdio/lib_libfread.c index a0aa588169e..d41639d8002 100644 --- a/libc/stdio/lib_libfread.c +++ b/libc/stdio/lib_libfread.c @@ -99,7 +99,7 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) #ifndef CONFIG_STDIO_DISABLE_BUFFERING /* Is there an I/O buffer? */ - if (stream->bufstart != NULL) + if (stream->fs_bufstart != NULL) { /* If the buffer is currently being used for write access, then * flush all of the buffered write data. We do not support concurrent @@ -202,7 +202,8 @@ 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 = read(stream->fs_fd, stream->fs_bufread, + buffer_available); if (bytes_read < 0) { /* An error occurred on the read. The error code is @@ -229,7 +230,10 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) } } } -#else + } + else +#endif + { /* Now get any other needed chars from the file. */ while (count > 0) @@ -259,7 +263,6 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) } } } -#endif /* Here after a successful (but perhaps short) read */ diff --git a/libc/stdio/lib_libfwrite.c b/libc/stdio/lib_libfwrite.c index 8cb067933fb..b8c90277e6e 100644 --- a/libc/stdio/lib_libfwrite.c +++ b/libc/stdio/lib_libfwrite.c @@ -63,7 +63,6 @@ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) FAR const unsigned char *src = ptr; ssize_t ret = ERROR; unsigned char *dest; - int ret; /* Make sure that writing to this stream is allowed */ @@ -153,7 +152,7 @@ ssize_t lib_fwrite(FAR const void *ptr, size_t count, FAR FILE *stream) /* Return the number of bytes written */ - ret = src - start; + ret = (uintptr_t)src - (uintptr_t)start; errout_with_semaphore: lib_give_semaphore(stream); diff --git a/libc/stdio/lib_rdflush.c b/libc/stdio/lib_rdflush.c index 284f59e7d7d..f6269833a13 100644 --- a/libc/stdio/lib_rdflush.c +++ b/libc/stdio/lib_rdflush.c @@ -65,7 +65,7 @@ int lib_rdflush(FAR FILE *stream) { /* Sanity checking */ - if (stream =- NULL) + if (stream == NULL) { set_errno(EBADF); return ERROR; diff --git a/libc/stdio/lib_setvbuf.c b/libc/stdio/lib_setvbuf.c index 10fbc0e6d0e..7d30a6ea883 100644 --- a/libc/stdio/lib_setvbuf.c +++ b/libc/stdio/lib_setvbuf.c @@ -132,7 +132,7 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) if ((mode == _IOFBF || mode == _IOLBF) && size == 0 && stream->fs_bufstart == NULL) { - size = BUFSIZE; + size = BUFSIZ; } /* Make sure that we have exclusive access to the stream */ @@ -169,7 +169,7 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) * successful. */ - flags = stream->fs_flags & ~(__FS_FLAG_LBF | __FS_FLAG_NBF | __FS_FLAG_UBF); + flags = stream->fs_flags & ~(__FS_FLAG_LBF | __FS_FLAG_UBF); /* Allocate a new buffer if one is needed or reuse the existing buffer it * is appropriate to do so. @@ -230,7 +230,6 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size) DEBUGASSERT(size == 0); newbuf = NULL; - flags |= __FS_FLAG_NBF; break; default: @@ -276,5 +275,3 @@ errout: return ERROR; #endif } - -#endif /* !CONFIG_STDIO_DISABLE_BUFFERING */ diff --git a/libc/stdio/lib_stdoutstream.c b/libc/stdio/lib_stdoutstream.c index 5884f70bf53..4c77c745fcc 100644 --- a/libc/stdio/lib_stdoutstream.c +++ b/libc/stdio/lib_stdoutstream.c @@ -86,19 +86,9 @@ static void stdoutstream_putc(FAR struct lib_outstream_s *this, int ch) static int stdoutstream_flush(FAR struct lib_outstream_s *this) { FAR struct lib_stdoutstream_s *sthis = (FAR struct lib_stdoutstream_s *)this; - FAR struct file *stream; DEBUGASSERT(sthis != NULL && sthis->stream != NULL); - stream = sthis->stream; - - if (stream->fs_bufstart != NULL) - { - return lib_fflush(sthis->stream, true); - } - else - { - return OK; - } + return lib_fflush(sthis->stream, true); } #endif diff --git a/libc/stdio/lib_stdsostream.c b/libc/stdio/lib_stdsostream.c index a9957f53c7c..8654b635620 100644 --- a/libc/stdio/lib_stdsostream.c +++ b/libc/stdio/lib_stdsostream.c @@ -85,20 +85,10 @@ static void stdsostream_putc(FAR struct lib_sostream_s *this, int ch) #ifndef CONFIG_STDIO_DISABLE_BUFFERING static int stdsostream_flush(FAR struct lib_sostream_s *this) { - FAR struct lib_stdsostream_s *sthis = (FAR struct lib_stdoutstream_s *)this; - FAR struct file *stream; + FAR struct lib_stdsostream_s *sthis = (FAR struct lib_stdsostream_s *)this; DEBUGASSERT(sthis != NULL && sthis->stream != NULL); - stream = sthis->stream; - - if (stream->fs_bufstart != NULL) - { - return lib_fflush(sthis->stream, true); - } - else - { - return OK; - } + return lib_fflush(sthis->stream, true); } #endif @@ -109,10 +99,10 @@ static int stdsostream_flush(FAR struct lib_sostream_s *this) static off_t stdsostream_seek(FAR struct lib_sostream_s *this, off_t offset, int whence) { - FAR struct lib_stdsostream_s *mthis = (FAR struct lib_stdsostream_s *)this; + FAR struct lib_stdsostream_s *sthis = (FAR struct lib_stdsostream_s *)this; - DEBUGASSERT(this); - return fseek(mthis->stream, offset, whence); + DEBUGASSERT(sthis != NULL && sthis->stream != NULL); + return fseek(sthis->stream, offset, whence); } /****************************************************************************