Apparently setvbuf() size can be nonzero with _IONBF. That makes no sense, but is necessary if setbuf() is to work as it is defined at OpenGroup.org.
This commit is contained in:
parent
ffbf6bc9a6
commit
98d072a1f7
@ -59,11 +59,7 @@
|
||||
*
|
||||
* setvbuf(stream, buf, _IONBF, BUFSIZ)
|
||||
*
|
||||
* if buf is a null pointer.
|
||||
*
|
||||
* EXCEPTION: Currently, the NuttX setvbuf() expects the size argument to
|
||||
* be zero if the mode is __INOBF. That is a descrepancy! What would a
|
||||
* non-zero size mean in that case?
|
||||
* if buf is a null pointer.
|
||||
*
|
||||
* Input Parameters:
|
||||
* stream - The stream whose buffer will be modified
|
||||
@ -77,16 +73,15 @@
|
||||
|
||||
void setbuf(FAR FILE *stream, FAR char *buf)
|
||||
{
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
int mode;
|
||||
|
||||
DEBUGASSERT(stream != NULL);
|
||||
|
||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||
if (buf != NULL)
|
||||
{
|
||||
(void)setvbuf(stream, buf, _IOFBF, BUFSIZ);
|
||||
}
|
||||
else
|
||||
{
|
||||
(void)setvbuf(stream, NULL, _IONBF, 0);
|
||||
}
|
||||
mode = (buf != NULL) ? _IOFBF : _IONBF;
|
||||
(void)setvbuf(stream, buf, mode, BUFSIZ);
|
||||
|
||||
#else
|
||||
DEBUGASSERT(stream != NULL);
|
||||
#endif
|
||||
}
|
||||
|
@ -113,16 +113,6 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* A non-zero size (or a non-NULL buffer) with mode = _IONBF makes no
|
||||
* sense.
|
||||
*/
|
||||
|
||||
if (mode == _IONBF && size > 0)
|
||||
{
|
||||
errcode = EINVAL;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* My assumption is that if size is zero for modes {_IOFBF, _IOLBF} the
|
||||
* caller is only attempting to change the buffering mode. In this case,
|
||||
* the existing buffer should be re-used (if there is one). If there is no
|
||||
@ -136,6 +126,17 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
|
||||
size = BUFSIZ;
|
||||
}
|
||||
|
||||
/* A non-zero size (or a non-NULL buffer) with mode = _IONBF makes no
|
||||
* sense but is, apparently, permissible. We simply force the buffer to
|
||||
* NULL and size to zero in this case without complaining.
|
||||
*/
|
||||
|
||||
else if (mode == _IONBF)
|
||||
{
|
||||
buffer = NULL;
|
||||
size = 0;
|
||||
}
|
||||
|
||||
/* Make sure that we have exclusive access to the stream */
|
||||
|
||||
lib_take_semaphore(stream);
|
||||
@ -229,7 +230,6 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
|
||||
case _IONBF:
|
||||
/* No buffer needed... We must be performing unbuffered I/O */
|
||||
|
||||
DEBUGASSERT(size == 0);
|
||||
newbuf = NULL;
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user