1setbuffer(3C)            Standard C Library Functions            setbuffer(3C)
2
3
4

NAME

6       setbuffer, setlinebuf - assign buffering to a stream
7

SYNOPSIS

9       #include <stdio.h>
10
11       void setbuffer(FILE *iop, char *abuf, size_t asize);
12
13
14       int setlinebuf(FILE *iop);
15
16

DESCRIPTION

18       The  setbuffer()  and  setlinebuf()  functions  assign  buffering  to a
19       stream. The three types of buffering available  are  unbuffered,  block
20       buffered,  and  line  buffered.  When  an  output stream is unbuffered,
21       information appears on the destination file  or  terminal  as  soon  as
22       written; when it is block buffered, many characters are saved and writ‐
23       ten as a block; when it is line buffered, characters  are  saved  until
24       either  a  NEWLINE  is  encountered  or  input  is read from stdin. The
25       fflush(3C) function may be used to force the block out early.  Normally
26       all files are block buffered. A buffer is obtained from malloc(3C) upon
27       the first getc(3C) or putc(3C) performed on the file. If  the  standard
28       stream  stdout  refers to a terminal, it is line buffered. The standard
29       stream stderr is unbuffered by default.
30
31
32       The setbuffer() function can be used after a stream iop has been opened
33       but  before  it  is  read  or written. It uses the character array abuf
34       whose size is determined by the asize argument instead of an  automati‐
35       cally allocated buffer.  If abuf is the null pointer, input/output will
36       be completely unbuffered. A manifest constant BUFSIZ,  defined  in  the
37       <stdio.h> header, tells how large an array is needed:
38
39
40       char buf[BUFSIZ];
41
42
43       The  setlinebuf()  function is used to change the buffering on a stream
44       from block buffered or unbuffered to line buffered. Unlike setbuffer(),
45       it can be used at any time that the stream iop is active.
46
47
48       A  stream  can  be  changed  from  unbuffered or line buffered to block
49       buffered by using freopen(3C). A  stream  can  be  changed  from  block
50       buffered  or  line buffered to unbuffered by using freopen(3C) followed
51       by setbuf(3C) with a buffer argument of NULL.
52

RETURN VALUES

54       The setlinebuf() function returns no useful value.
55

SEE ALSO

57       malloc(3C), fclose(3C),  fopen(3C),  fread(3C),  getc(3C),  printf(3C),
58       putc(3C), puts(3C), setbuf(3C), setvbuf(3C)
59

NOTES

61       A  common  source of error is allocating buffer space as an "automatic"
62       variable in a code block, and then failing to close the stream  in  the
63       same block.
64
65
66
67SunOS 5.11                        13 May 1997                    setbuffer(3C)
Impressum