mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 11:26:12 +08:00
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:
+9
-14
@@ -59,11 +59,7 @@
|
|||||||
*
|
*
|
||||||
* setvbuf(stream, buf, _IONBF, BUFSIZ)
|
* setvbuf(stream, buf, _IONBF, BUFSIZ)
|
||||||
*
|
*
|
||||||
* if buf is a null pointer.
|
* 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?
|
|
||||||
*
|
*
|
||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* stream - The stream whose buffer will be modified
|
* stream - The stream whose buffer will be modified
|
||||||
@@ -77,16 +73,15 @@
|
|||||||
|
|
||||||
void setbuf(FAR FILE *stream, FAR char *buf)
|
void setbuf(FAR FILE *stream, FAR char *buf)
|
||||||
{
|
{
|
||||||
|
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
||||||
|
int mode;
|
||||||
|
|
||||||
DEBUGASSERT(stream != NULL);
|
DEBUGASSERT(stream != NULL);
|
||||||
|
|
||||||
#ifndef CONFIG_STDIO_DISABLE_BUFFERING
|
mode = (buf != NULL) ? _IOFBF : _IONBF;
|
||||||
if (buf != NULL)
|
(void)setvbuf(stream, buf, mode, BUFSIZ);
|
||||||
{
|
|
||||||
(void)setvbuf(stream, buf, _IOFBF, BUFSIZ);
|
#else
|
||||||
}
|
DEBUGASSERT(stream != NULL);
|
||||||
else
|
|
||||||
{
|
|
||||||
(void)setvbuf(stream, NULL, _IONBF, 0);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|||||||
+11
-11
@@ -113,16 +113,6 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
|
|||||||
goto errout;
|
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
|
/* 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,
|
* 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
|
* 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;
|
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 */
|
/* Make sure that we have exclusive access to the stream */
|
||||||
|
|
||||||
lib_take_semaphore(stream);
|
lib_take_semaphore(stream);
|
||||||
@@ -229,7 +230,6 @@ int setvbuf(FAR FILE *stream, FAR char *buffer, int mode, size_t size)
|
|||||||
case _IONBF:
|
case _IONBF:
|
||||||
/* No buffer needed... We must be performing unbuffered I/O */
|
/* No buffer needed... We must be performing unbuffered I/O */
|
||||||
|
|
||||||
DEBUGASSERT(size == 0);
|
|
||||||
newbuf = NULL;
|
newbuf = NULL;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user