SETBUF(3s,L) AIX Technical Reference SETBUF(3s,L) ------------------------------------------------------------------------------- setbuf, setvbuf PURPOSE Assigns buffering to a stream. LIBRARY Standard I/O Library (libc.a) SYNTAX #include void setbuf (stream, buf) FILE *stream; char *buf; int setvbuf (stream, buf, mode, size) FILE *stream; char *buf; int mode; size_t size; DESCRIPTION The setbuf and setvbuf functions override the default buffering on the specified stream. These functions may be used only after the stream pointed to by stream has been associated with an open file and before any other operation is performed on the stream. If setbuf and setvbuf are not called prior to the first time the stream is read or written, a buffer will be allocated automatically. For streams directed to terminals, this will enable line buffering; except for stderr which is unbuffered by default. The setbuf subroutine causes the user supplied buffer buf to be used instead of the default buffer. This buffer must be of size BUFSIZ characters, as defined in . If the buf parameter is a NULL pointer, the stream will be unbuffered. For the setvbuf function, mode determines how stream is buffered: _IOFBF Causes input/output to be fully buffered. _IOLBF Causes input/output to be line buffered. The buffer is flushed when a new line is written, the buffer is full, or input is requested. _IONBF Causes input/output to be completely unbuffered. Processed April 9, 1991 SETBUF(3s,L) 1 SETBUF(3s,L) AIX Technical Reference SETBUF(3s,L) For fully buffered and line buffered streams, a non-null buf parameter may be specified. It must point to an array of size characters to be used for the buffering; or a null buf parameter may be specified to request that setvbuf, allocate its own buffer of size size. A good value for size is the constant BUFSIZ defined in . If input/output is unbuffered, the buf and size parameters are ignored. Note: 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. ERROR CONDITIONS The setvbuf function fails and returns -1 if any of the function arguments is invalid, otherwise, it succeeds and returns 0. RELATED INFORMATION In this book: "fopen, freopen, fdopen," "getc, fgetc, getchar, getw, getwc, fgetwc, getwchar," "malloc, free, realloc, calloc, valloc, alloca, mallopt, mallinfo," "putc, putchar, fputc, putw, putwc, putwchar, fputwc," "setbuffer, setlinebuf," and "stdio." Processed April 9, 1991 SETBUF(3s,L) 2