CKTIS / C
setbuf — configuring stream buffering
`setbuf` from `<stdio.h>` requests full buffering if `buf` is non-null, or unbuffered operation if `buf` is `NULL`. The implementation may use the supplied array but is not required to. The function does not report whether the request was honored.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <stdio.h>
void setbuf(FILE * restrict stream, char * restrict buf);setbuf(stream, buf) requests a buffering mode for an open stream. A non-null buf requests full buffering (_IOFBF) with size BUFSIZ. The implementation may use the supplied array as the buffer but is not required to. Passing NULL requests unbuffered operation (_IONBF).
Call it before any other operation on the stream, except for an unsuccessful call to setvbuf. If buf is non-null, it must point to a writable array of at least BUFSIZ bytes that remains alive until the stream is closed. The array's contents are unspecified.
The function returns void, so it cannot report whether the request was honored. setvbuf returns a status code, lets you select the buffer size, and supports line buffering (_IOLBF).
Examples
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
static char buffer[BUFSIZ];
setbuf(stdout, buffer);
if (puts("Hello") == EOF) {
return EXIT_FAILURE;
}
if (fflush(stdout) == EOF) {
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}Result
Hello
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.