1setbuf(3)                  Library Functions Manual                  setbuf(3)
2
3
4

NAME

6       setbuf, setbuffer, setlinebuf, setvbuf - stream buffering operations
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

12       #include <stdio.h>
13
14       int setvbuf(FILE *restrict stream, char buf[restrict .size],
15                   int mode, size_t size);
16
17       void setbuf(FILE *restrict stream, char *restrict buf);
18       void setbuffer(FILE *restrict stream, char buf[restrict .size],
19                   size_t size);
20       void setlinebuf(FILE *stream);
21
22   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
23
24       setbuffer(), setlinebuf():
25           Since glibc 2.19:
26               _DEFAULT_SOURCE
27           glibc 2.19 and earlier:
28               _BSD_SOURCE
29

DESCRIPTION

31       The  three types of buffering available are unbuffered, block buffered,
32       and line buffered.  When an output stream  is  unbuffered,  information
33       appears on the destination file or terminal as soon as written; when it
34       is block buffered, many characters are saved up and written as a block;
35       when  it  is  line buffered, characters are saved up until a newline is
36       output or input is read from any stream attached to a  terminal  device
37       (typically  stdin).   The  function  fflush(3) may be used to force the
38       block out early.  (See fclose(3).)
39
40       Normally all files are block buffered.  If a stream refers to a  termi‐
41       nal (as stdout normally does), it is line buffered.  The standard error
42       stream stderr is always unbuffered by default.
43
44       The setvbuf() function may be used on any open  stream  to  change  its
45       buffer.  The mode argument must be one of the following three macros:
46
47              _IONBF unbuffered
48
49              _IOLBF line buffered
50
51              _IOFBF fully buffered
52
53       Except  for unbuffered files, the buf argument should point to a buffer
54       at least size bytes long; this buffer will be used instead of the  cur‐
55       rent buffer.  If the argument buf is NULL, only the mode is affected; a
56       new buffer will be allocated on the next read or write operation.   The
57       setvbuf()  function  may be used only after opening a stream and before
58       any other operations have been performed on it.
59
60       The other three calls are, in  effect,  simply  aliases  for  calls  to
61       setvbuf().  The setbuf() function is exactly equivalent to the call
62
63           setvbuf(stream, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
64
65       The  setbuffer() function is the same, except that the size of the buf‐
66       fer is up to the caller, rather than being determined  by  the  default
67       BUFSIZ.  The setlinebuf() function is exactly equivalent to the call:
68
69           setvbuf(stream, NULL, _IOLBF, 0);
70

RETURN VALUE

72       The  function  setvbuf()  returns  0 on success.  It returns nonzero on
73       failure (mode is invalid or the request cannot be honored).  It may set
74