HP C/iX Library Reference Manual (30026-90004)
16 Chapter2
HP C/iX Library Input and Output
HP C/iX Library Input and Output
of which is six characters in length, the result is different. Assume the same five
characters are written. When the C I/O system encounters the \n, it gets ready to write out
a record. The record contains "ABCD" at this point. However, since the record is a
fixed-length record with a length of six characters, the two characters after the 'D are
padded with spaces (040). The record written to the MPE file is:
ABCD
where indicates a space. As before, the \n triggers the write, but the actual \n character
is not written out.
When the record is read back into the program, the \n is restored at the end of the record,
but the I/O functions have no way of knowing whether the trailing spaces are pad
characters written by the MPE/iX file system, or actual data characters written by a C
program. This ambiguity is resolved in one of two ways (described below), depending on
whether ANSI-conformant behavior has been requested.
The standard ANSI conformant interpretation, which is requested by including
LIBCANSI.LIB.SYS in the RL list when linking (as described in chapter 1), is to discard all
trailing spaces in fixed-length records when reading text streams. In the example given
above, the result is that the following five characters are read back:
`A', `B', `C', `D', `\n'
However, for compatibility with previous releases of the HP C/iX library, the default
behavior is that trailing spaces in fixed-length records in text files are not stripped. Thus,
if the program in the example is not linked with LIBCANSI, it reads the following seven
characters:
`A', `B', `C', 'D', space, space, `\n'
Because of the special meaning of the \n character, in text streams, you should avoid
writing binary data to a text stream. If the binary data happens to contain a byte with the
same numeric value as the newline character (ASCII code 10), the result is an unexpected
record break.
Binary Streams
Like text streams, binary streams are also ordered sequence of bytes. Binary streams,
however, transparently record data. No special attention is given to \n characters or any
other characters. No padding is performed for binary streams.
If a \n character is written to a binary stream, it is actually written. Binary streams
return the same number of characters originally written except in one special case.
On MPE/iX, if fopen() opens a binary stream it is a fixed-length record format file. If the
file is closed, the last record in the file, if incomplete, is filled with trailing zeros. The
end-of-file is located on a record boundary, regardless of the last byte written to the file.
By default, if you are using POSIX on MPE/iX, fopen() creates a byte stream file. If the
file is closed, the last byte written is the end-of-file.
File Descriptors
To perform I/O operations, you must associate a stream with a file or device. For the
unbuffered I/O operations (the ones in the standard I/O library), you do this by declaring a