Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)
OSS Library Calls (e - f) fopen_oss(3)
r+ Open an existing file for update access (reading and writing).
w+ Create a file (or truncate an existing file to length zero) and open it for update
access.
a+ Create a file (or open an existing file) and open it for update access with writing
at the end of the file.
The OSS version of fopen does not distinguish between text and binary files. Text and binary
files are type 180. Specifying a value of mode that consists of an r, w,ora followed by a b indi-
cates a binary file. However, the OSS version of the fopen function ignores the b in the value of
mode.
When you open a file for update, you can perform both input and output operations on the result-
ing stream. However, an input operation cannot directly follow an output operation without an
intervening fflush( ) function call or a file-positioning operation (fseek( ), fsetpos( ),orrewind()
function). Also, an output operation cannot directly follow an input operation without an inter-
vening flush or file-positioning operation, unless the input operation encounters the end of the
file.
When you open a file for append (that is, when the mode parameter is a or a+), it is impossible to
overwrite information already in the file. You can use the fseek( ) function to reposition the file
pointer to any position in the file, but when output is written to the file, the current file pointer is
ignored. All output is written at the end of the file and the file pointer is repositioned to the end
of the output.
If two separate processes open the same file for append, each process can write freely to the file
without destroying the output being written by the other. The output from the two processes is
intermixed in the order in which it is written to the file. Note that if the data is buffered, it is not
actually written until it is flushed.
When opened, a stream is fully buffered if and only if it does not refer to an interactive device.
The error and End-of-File indicators for the stream are cleared.
If the mode parameter is w, a, w+,ora+ and the file did not previously exist, upon successful
completion the fopen( ) function marks the st_atime, st_ctime and st_mtime fields of the file
and the st_ctime and st_mtime fields of the parent directory for update. If the mode parameter is
w or w+ and the file did previously exist, upon successful completion the fopen( ) function marks
the st_ctime and st_mtime fields of the file for update.
Interoperability Variants
The C run-time library supports two variants of the fopen( ) function:
fopen_oss( ) and
f
op
en_guardian( ). The variants support the unique file naming conventions and structures of the
OSS and Guardian file systems, respectively.
For the TNS C runtime library only, the header file maps calls to fopen( ) to the variant that
matches the target compilation environment. The target environment is set with the systype
pragma.
Explicit calls to the fopen_oss( ) and fopen_guardian( ) variants in source code are only made
when the behavior of one environment is desired from the other environment.
fopen_oss( ) is functionally identical to the fopen( ) function of the OSS environment. It is the
same as setting systype oss at compile-time. systype oss is the default setting for c89 in
the OSS environment and on UNIX workstations.
fopen_guardian( ) is functionally identical to the fopen( ) function of the Guardian environment.
It is the same as setting systype guardian at compile-time. systype guardian is the
default setting for the C and C++ compilers in the Guardian environment.
527187-017 Hewlett-Packard Company 2−117