setvbuf: Fix some compile errors in first build of logic to enable/disable buffering.

This commit is contained in:
Gregory Nutt 2017-02-09 09:53:50 -06:00
parent 1d290c2b37
commit 889ff4b01e
6 changed files with 17 additions and 38 deletions

View File

@ -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 */

View File

@ -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);

View File

@ -65,7 +65,7 @@ int lib_rdflush(FAR FILE *stream)
{
/* Sanity checking */
if (stream =- NULL)
if (stream == NULL)
{
set_errno(EBADF);
return ERROR;

View File

@ -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 */

View File

@ -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

View File

@ -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);
}
/****************************************************************************