Buffering of C streams
This topic describes buffering modes used by z/OS® XL C/C++ library functions available to control buffering and methods of flushing buffers.
- Line buffering - characters are transmitted to the system as a block when a new-line character is encountered. Line buffering is meaningful only for text streams and UNIX file system files.
- Full buffering - characters are transmitted to the system as a block when a buffer is filled.
- No buffering - characters are transmitted to the system as they are written. Only regular memory files and UNIX file system files support the no buffering mode.
- If you are using an interactive terminal, z/OS XL C/C++ uses line buffering.
- If you are running under CICS®, z/OS XL C/C++ also uses line buffering.
- stderr is line-buffered by default.
- If you are using a memory file, z/OS XL C/C++ does not use any buffering.
For record I/O files, buffering is meaningful only for blocked files or for record I/O files in z/OS UNIX file system using full buffering. For unblocked files, the buffer is full after every write and is therefore written immediately, leaving nothing to flush. For blocked files or fully-buffered UNIX file system files, however, the buffer can contain one or more records that have not been flushed and that require a flush operation for them to go to the system.
For blocked I/O files, buffering is always meaningless.
- If you are using full buffering, z/OS XL C/C++ automatically flushes a buffer when it is filled.
- If you are using line buffering for a text file or a UNIX file system file, z/OS XL C/C++ flushes a buffer when you complete it with a control character. Except for UNIX file system files, specifying line buffering for a record I/O, blocked I/O, or binary file has no effect; z/OS XL C/C++ treats the file as if you had specified full buffering.
- z/OS XL C/C++ flushes buffers to the system when you close a file or end a program.
- z/OS XL C/C++ flushes buffers to the system
when you call the fflush() library
function, with the following restrictions:
- A file opened in text mode does not flush data if a record has not been completed with a new-line.
- A file opened in fixed format does not flush incomplete records to the file.
- An FBS file does not flush out a short block unless it is a DISK file opened without the NOSEEK parameter.
- All streams are flushed across non-POSIX system() calls. Streams are not flushed across POSIX system() calls. For a POSIX system call, we recommend that you do a fflush() before the system() call.
You may not see output if a program that is using input and output fails, and the error handling routines cannot close all the open files.