lib_libfread.c: nxstyle fixes

This commit is contained in:
YAMAMOTO Takashi
2020-07-30 16:55:28 +09:00
committed by Alin Jerpelea
parent d02354c766
commit 15590005d0
+21 -18
View File
@@ -60,7 +60,7 @@
ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream) ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
{ {
FAR unsigned char *dest = (FAR unsigned char*)ptr; FAR unsigned char *dest = (FAR unsigned char *)ptr;
ssize_t bytes_read; ssize_t bytes_read;
size_t remaining = count; size_t remaining = count;
#ifndef CONFIG_STDIO_DISABLE_BUFFERING #ifndef CONFIG_STDIO_DISABLE_BUFFERING
@@ -104,8 +104,8 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
if (stream->fs_bufstart != NULL) if (stream->fs_bufstart != NULL)
{ {
/* If the buffer is currently being used for write access, then /* If the buffer is currently being used for write access, then
* flush all of the buffered write data. We do not support concurrent * flush all of the buffered write data. We do not support
* buffered read/write access. * concurrent buffered read/write access.
*/ */
ret = lib_wrflush(stream); ret = lib_wrflush(stream);
@@ -129,8 +129,8 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
remaining--; remaining--;
} }
/* The buffer is empty OR we have already supplied the number of /* The buffer is empty OR we have already supplied the number
* bytes requested in the read. Check if we need to read * of bytes requested in the read. Check if we need to read
* more from the file. * more from the file.
*/ */
@@ -138,11 +138,14 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
{ {
size_t buffer_available; size_t buffer_available;
/* We need to read more data into the buffer from the file */ /* We need to read more data into the buffer from the
* file
*/
/* Mark the buffer empty */ /* Mark the buffer empty */
stream->fs_bufpos = stream->fs_bufread = stream->fs_bufstart; stream->fs_bufpos = stream->fs_bufread =
stream->fs_bufstart;
/* How much space is available in the buffer? */ /* How much space is available in the buffer? */
@@ -166,17 +169,17 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
} }
else if (bytes_read == 0) else if (bytes_read == 0)
{ {
/* We are at the end of the file. But we may already /* We are at the end of the file. But we may
* have buffered data. In that case, we will report * already have buffered data. In that case,
* the EOF indication later. * we will report the EOF indication later.
*/ */
goto shortread; goto shortread;
} }
else else
{ {
/* Some (perhaps all) bytes were read. Adjust the dest /* Some (perhaps all) bytes were read. Adjust the
* pointer and remaining bytes to be read. * dest pointer and remaining bytes to be read.
*/ */
DEBUGASSERT(bytes_read <= remaining); DEBUGASSERT(bytes_read <= remaining);
@@ -197,8 +200,8 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
buffer_available); buffer_available);
if (bytes_read < 0) if (bytes_read < 0)
{ {
/* An error occurred on the read. The error code is /* An error occurred on the read. The error code
* in the 'errno' variable. * is in the 'errno' variable.
*/ */
_NX_SETERRNO(bytes_read); _NX_SETERRNO(bytes_read);
@@ -206,9 +209,9 @@ ssize_t lib_fread(FAR void *ptr, size_t count, FAR FILE *stream)
} }
else if (bytes_read == 0) else if (bytes_read == 0)
{ {
/* We are at the end of the file. But we may already /* We are at the end of the file. But we may
* have buffered data. In that case, we will report * already have buffered data. In that case,
* the EOF indication later. * we will report the EOF indication later.
*/ */
goto shortread; goto shortread;
@@ -285,7 +288,7 @@ shortread:
return count - remaining; return count - remaining;
/* Error exits */ /* Error exits */
errout_with_errno: errout_with_errno:
stream->fs_flags |= __FS_FLAG_ERROR; stream->fs_flags |= __FS_FLAG_ERROR;