#define BUFSIZ /*unspecified*/
Sets the internal buffer to use for stream operations. It should be at least BUFSIZ
characters long.
If buffer
is not null, equivalent to setvbuf(stream, buffer, _IOFBF, BUFSIZ).
If buffer
is null, equivalent to setvbuf(stream, NULL, _IONBF, 0), which turns off buffering.
None.
[edit] NotesIf BUFSIZ is not the appropriate buffer size, setvbuf can be used to change it.
setvbuf should also be used to detect errors, since setbuf
does not indicate success or failure.
This function may only be used after stream
has been associated with an open file, but before any other operation (other than a failed call to setbuf/setvbuf
).
A common error is setting the buffer of stdin or stdout to an array whose lifetime ends before the program terminates:
int main(void) { char buf[BUFSIZ]; setbuf(stdin, buf); } // lifetime of buf ends, undefined behavior[edit] Example
setbuf
may be used to disable buffering on streams that require immediate output.
#include <stdio.h> #include <threads.h> int main(void) { setbuf(stdout, NULL); // unbuffered stdout putchar('a'); // 'a' appears immediately if stdout is unbuffered thrd_sleep(&(struct timespec){.tv_sec=1}, NULL); // sleep 1 sec putchar('b'); }
Output:
[edit] ReferencesRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4