Buffering

z/OS® XL C/C++ uses buffers to map C I/O to system-level I/O. When z/OS XL C/C++ performs I/O operations, it uses one of the following buffering modes:

C/C++ provides a third buffering mode, unbuffered I/O, which is not supported for OS files.

You can use the setvbuf() and setbuf() library functions to set the buffering mode before you perform any I/O operation to the file. setvbuf() fails if you specify unbuffered I/O. It also fails if you try to specify line buffering for an FBS data set opened in text mode, where the device does not support repositioning. This failure happens because z/OS XL C/C++ cannot deliver records at line boundaries without violating FBS format. Do not try to change the buffering mode after you have performed any I/O operation to the file.

For all files except stderr, full buffering is the default, but you can use setvbuf() to specify line buffering. For binary files, record I/O files, and unblocked text files, a block is written out as soon as it is full, regardless of whether you have specified line buffering or full buffering. For blocked I/O files, a block is written out as soon as fwrite() completes. Line buffering is different from full buffering only for blocked text files.