01.01.2013 Views

AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox

AT&T UNIX™PC Unix System V Users Manual - tenox

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

�<br />

I<br />

SETBUF (3S) SETBUF (3S)<br />

NAME setbuf - assign buffering to a stream<br />

SYNOPSIS<br />

#include <br />

void setbuf (stream, buf)<br />

FILE •stream;<br />

char •buf;<br />

int setvbuf (stream, buf, type, size)<br />

FILE *stream;<br />

char *buf;<br />

int type, size;<br />

DESCRIPTION<br />

Setbuj is used after a stream has been opened but before it is read<br />

or written. It causes the character array pointed to by buf to be<br />

used instead of an automatically allocated buffer. If buf is a NULL<br />

character pointer input/output will be completely unbuffered.<br />

A constant BUFSIZ, defined in the header file, tells<br />

how big an array is needed:<br />

char buf[BUFSIZ] ;<br />

Setbuf may be used after a stream has been opened but before it is<br />

read or written. Type determines how stream will be buffered.<br />

Legal values for type (defined in stdio.h) are:<br />

_IOFBF causes input to be fully buffered.<br />

_IOLBF causes output to be line buffered; the buffer will be<br />

flushed when a new line is written, the buffer is full, or<br />

input is requested.<br />

JONBF causes input and output to be completely unbuffered.<br />

A buffer is normally obtained from malloc(3C) at the time of the<br />

first getc or putc(3S) on the file, except that the standard error<br />

stream stderr is normally not buffered.<br />

Output streams directed to terminals are always line-buffered<br />

unless they are unbuffered.<br />

SEE ALSO<br />

fopen(3S), getc(3S), malloc(3C), putc(3S).<br />

NOTE<br />

A common source of error is allocating buffer space as an<br />

"automatic" variable in a code block, and then failing to close the<br />

stream in the same block.<br />

- 1 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!