Writing to files

You can use the following library functions to write to a file:

fwrite() is the only interface allowed for writing to record I/O or blocked I/O files. See z/OS XL C/C++ Runtime Library Reference for more information on these library functions.

A write operation directly after a read operation without an intervening call to fflush(), fsetpos(), fseek(), or rewind() fails unless the read operation has reached EOF. The file pointer does not reach EOF until after you have tried to read past the last byte of the file.

z/OS® XL C/C++ counts a call to a write function writing 0 bytes or a write request that fails because of a system error as a write operation.

If you are updating a file and a system failure occurs, z/OS XL C/C++ tries to set the file position to the end of the last record updated successfully. For a fully-buffered file, this is at the end of the last record in a block. For a line-buffered file, this may be any record in the current block. If you are writing new data at the time of a system failure, z/OS XL C/C++ puts the file position at the end of the last block of the file. In files opened for blocked output, you may lose data written by other writes to that block before the system failure. The contents of a file after a system write failure are indeterminate.

If one user opens a file for writing, and another later opens the same file for reading, the user who is reading the file can check for records that may have been written past the end of the file by the other user. If the file is a spanned variable text file, the reader can read part of a spanned record and reach the end of the file before reading in the last segment of the spanned record.