unixdev.net


Switch to SpeakEasy.net DSL

The Modular Manual Browser

Home Page
Manual: (SunOS-4.1.3)
Page:
Section:
Apropos / Subsearch:
optional field

SETBUF(3V)                                                          SETBUF(3V)



NAME
       setbuf, setbuffer, setlinebuf, setvbuf - assign buffering to a stream

SYNOPSIS
       #include <&lt;stdio.h>&gt;

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

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

       int setlinebuf(stream) FILE *stream;

       int setvbuf(stream, buf, type, size)
       FILE *stream;
       char *buf;
       int type, size;

DESCRIPTION
       The  three types of buffering available are unbuffered, block buffered,
       and line buffered.  When an output stream  is  unbuffered,  information
       appears on the destination file or terminal as soon as written; when it
       is block buffered many characters are saved up and written as a  block;
       when  it  is  line  buffered characters are saved up until a NEWLINE is
       encountered or input is read from stdin.  fflush() (see fclose(3V)) may
       be  used  to force the block out early.  A buffer is obtained from mal-
       loc(3V) upon the first getc(3V) or putc(3S) on the file.   By  default,
       output  to  a terminal is line buffered, except for output to the stan-
       dard stream stderr which is  unbuffered.   All  other  input/output  is
       fully buffered.

       setbuf()  can  be  used after a stream has been opened but before it is
       read or written.  It causes the array pointed to  by  buf  to  be  used
       instead  of  an  automatically  allocated  buffer.   If buf is the NULL
       pointer, input/output will be completely unbuffered.  A  manifest  con-
       stant  BUFSIZ,  defined  in the <&lt;stdio.h>&gt; header file, tells how big an
       array is needed:

              char buf[BUFSIZ];

       setbuffer(), an alternate form of setbuf(), can be used after a  stream
       has  been opened but before it is read or written.  It uses the charac-
       ter array buf whose size is determined by the size argument instead  of
       an  automatically  allocated  buffer.   If  buf  is  the  NULL pointer,
       input/output will be completely unbuffered.

       setvbuf() can be used after a stream has been opened but before  it  is
       read  or  written.  type determines how stream will be buffered.  Legal
       values for type (defined in <&lt;stdio.h>&gt;) are:

       _IOFBF  fully buffers the input/output.

       _IOLBF  line buffers the output; the buffer will be flushed when a NEW-
               LINE is written, the buffer is full, or input is requested.

       _IONBF  completely unbuffers the input/output.

       If buf is not the NULL pointer, the array it points to will be used for
       buffering, instead of an automatically allocated buffer.   size  speci-
       fies the size of the buffer to be used.

       setlinebuf()  is  used  to  change the buffering on a stream from block
       buffered or unbuffered to line buffered.  Unlike setbuf(), setbuffer(),
       and  setvbuf(),  it can be used at any time that the file descriptor is
       active.

       A file can be  changed  from  unbuffered  or  line  buffered  to  block
       buffered  by  using  freopen()  (see fopen(3V)).  A file can be changed
       from block buffered or line buffered to unbuffered by  using  freopen()
       followed by setbuf() with a buffer argument of NULL.

SYSTEM V DESCRIPTION
       If  buf  is  not  NULL and stream refers to a terminal device, setbuf()
       sets stream for line buffered input/output.

RETURN VALUES
       setlinebuf() returns no useful value.

       setvbuf() returns 0 on success.  If an illegal value for type  or  size
       is provided, setvbuf() returns a non-zero value.  setvbuf()

SEE ALSO
       fclose(3V),  fopen(3V),  fread(3S),  getc(3V),  malloc(3V), printf(3V),
       putc(3S), puts(3S)

NOTES
       A common source of error is allocating buffer space as  an  "automatic"
       variable  in  a code block, and then failing to close the stream in the
       same block.



                                21 January 1990                     SETBUF(3V)