HP C/iX Library Reference Manual (30026-90004)

310 Chapter5
HP C/iX Library Function Descriptions
setvbuf
identical:
setvbuf(fp, NULL, _IONBF, 0)
setbuf(fp, NULL)
When
type
is _IOFBF or _IOLBF, buffering for
stream
is determined by
buffer
and
size.
If
buffer
is not the null pointer, it must point to a character array of
size
bytes. All
buffering of
stream
is then handled through this array.
FILE *fp;
char buffer [256]
char *filename;
int retcode;
fp=fopen(filename, "w");
retcode=setvbuf(fp, buffer, _IOFBF, 256);
if (retcode !=0) error ();
This fragment causes stream fp to be buffered through the 256-byte array
buffer.
Serious run-time errors can occur if the buffer array is not the size specified in the call to
setvbuf() (here 256 bytes). As with setbuf, it is dangerous to use an automatic array for
the buffer. Note that the return value of setvbuf() can be used to verify that the request
was completed successfully.
FILE * fp;
char * filename;
int retcode;
fp = fopen(filename, "rt")
retcode=setvbuf(fp, NULL, _IOFBF, 2048);
if(retcode !=0) error( );
This fragment buffers stream fp through a 2048-byte buffer that is allocated by the
system.
See Also
setbuf(), ANSI C 4.9.5.6