OpenBSD manual page server

Manual Page Search Parameters

SETBUF(3) Library Functions Manual SETBUF(3)

setbuf, setbuffer, setlinebufstream buffering operations

#include <stdio.h>

void
setbuf(FILE *stream, char *buf);

void
setbuffer(FILE *stream, char *buf, size_t size);

int
setlinebuf(FILE *stream);

These interfaces are obsoleted by setvbuf(3).

The (), setbuffer(), and setlinebuf() functions are used to modify the buffering of a stream. These functions are provided for compatibility with legacy code. New code should use setvbuf(3) instead.

Except for the lack of a return value, the () function is exactly equivalent to the call

setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);

The () function is the same, except that the size of the buffer is up to the caller, rather than being determined by the default BUFSIZ.

The () function is exactly equivalent to the call:

setvbuf(stream, NULL, _IOLBF, 0);

Upon successful completion, the setlinebuf() function returns 0. If the request cannot be honored, a non-zero value is returned, possibly setting errno to indicate the error. The stream is not modified in the error case.

The setbuf(), setbuffer(), and setlinebuf() functions will fail if:

[]
The stream specified is not associated with a valid file descriptor.

fclose(3), fopen(3), fread(3), malloc(3), printf(3), puts(3), setvbuf(3)

The setbuf() function conforms to ISO/IEC 9899:1999 (“ISO C99”). The setbuffer() and setlinebuf() functions are non-standard and should not be used if portability is required.

The setbuf() function first appeared in Version 7 AT&T UNIX. The setbuffer() function first appeared in 4.1cBSD. The setlinebuf() function first appeared in 4.2BSD.

The setbuf() function usually uses a suboptimal buffer size and should be avoided.

November 25, 2014 OpenBSD-7.3