SETBUF(3S) UNIX Programmer's Manual SETBUF(3S) NAME setbuf, setvbuf - assign buffering to a stream SYNOPSIS #include void setbuf (stream, buf) FILE *stream; char *buf; int setvbuf (stream, buf, type, size) FILE *stream; char *buf; int type, size; COMPATIBILITY Level: HP-UX/RUN ONLY Origin: System III DESCRIPTION _S_e_t_b_u_f may be used after a stream has been opened but before it is read or written. It causes the array pointed to by _b_u_f to be used instead of an automatically allocated buffer. If _b_u_f is the NULL pointer input/output will be completely unbuffered. A constant BUFSIZ, defined in the header file, tells how big an array is needed: char buf[BUFSIZ]; _S_e_t_v_b_u_f may be used after a stream has been opened but before it is read or written. _T_y_p_e determines how _s_t_r_e_a_m will be buffered. Legal values for _t_y_p_e (defined in stdio.h) are: _IOFBF causes input/output to be fully buffered. _IOLBF causes output to be line buffered; the buffer will be flushed when a newline is written, the buffer is full, or input is requested. _IONBF causes input/output to be completely unbuffered. If _b_u_f is not the NULL pointer, the array it points to will be used for buffering, instead of an automati- cally allocated buffer. _S_i_z_e specifies the size of the buffer to be used. The constant BUFSIZ in is suggested as a good buffer size. If input/output is unbuffered, _b_u_f and _s_i_z_e are ignored. By default, output to a terminal is line buffered and all other input/output is fully buf- fered. SEE ALSO fopen(3S), getc(3S), malloc(3C), putc(3S), stdio(3S). DIAGNOSTICS If an illegal value for _t_y_p_e or _s_i_z_e is provided, or alloca- tion fails when bug==NULL, _s_e_t_v_b_u_f returns a non-zero value. Otherwise, the value returned will be zero. 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.