SETBUF(3)

NAME
setbuf, setbuffer, setlinebuf - stream buffering operations

SYNOPSIS
#include <stdio.h>
void
setbuf(FILE *stream, char *buf);
void
setbuffer(FILE *stream, char *buf, size_t size);
int
setlinebuf(FILE *stream);

DESCRIPTION
These interfaces are obsoleted by setvbuf(3).

The setbuf(), 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 setbuf() function is exactly equivalent to the call

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

The setbuffer() 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 setlinebuf() function is exactly equivalent to the call:

    setvbuf(stream, NULL, _IOLBF, 0);

RETURN VALUES
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.

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

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

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

STANDARDS
The setbuf() function conforms to isoC-99. The setbuffer() and setlinebuf() functions are non-standard and should not be used if portability is required.

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

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