CKTIS / C
stdio buffering constants
Macros from <stdio.h> select a stream's buffering mode and specify the buffer size for setbuf. Do not assume their numeric values.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <stdio.h>
int setvbuf(FILE * restrict stream, char * restrict buf, int mode, size_t size);
void setbuf(FILE * restrict stream, char * restrict buf);_IOFBF selects full buffering, _IOLBF line buffering, and _IONBF no buffering. They are mode arguments to setvbuf. BUFSIZ specifies the buffer size for setbuf, is at least 256, and is not a mode.
Full buffering intends block transfers when the buffer fills; line buffering also on \n; unbuffered streams transfer as soon as possible. Details depend on the implementation. fflush sends pending output to the environment, without guaranteeing durable disk storage.
Call setvbuf after opening the stream, before other operations except an unsuccessful setvbuf. Zero means success. A supplied array must remain available while the stream uses it. setbuf(stream, buf) selects _IOFBF and BUFSIZ; setbuf(stream, NULL) selects _IONBF, without reporting errors.
Examples
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
static char buffer[BUFSIZ];
if (setvbuf(stdout, buffer, _IOFBF, sizeof buffer) != 0)
return EXIT_FAILURE;
if (fputs("Buffered output\n", stdout) == EOF)
return EXIT_FAILURE;
if (fflush(stdout) == EOF)
return EXIT_FAILURE;
return EXIT_SUCCESS;
}Result
Buffered output
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.