Guardian Native C Library Calls Reference Manual (G06.28+, H06.04+)

Guardian Native C Library Calls (f) fdopen(3)
NAME
fdopen - Associates a stream with a le descriptor
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
H-series OSS processes: /G/system/zdllnnn/zcrtldll
SYNOPSIS
#include <stdio.h>
FILE fdopen(
int filedes,
const char mode);
PARAMETERS
mode Points to a character string that controls whether the le is opened for reading
(r), writing (w), or appending (a) and whether the le is opened for updating (+).
filedes Species a valid open le descriptor.
DESCRIPTION
The fdopen() function associates a stream with a le descriptor obtained from an open(), dup(),
creat(),orpipe( ) function. These functions open les, but do not return pointers to FILE struc-
tures. Many of the standard I/O package functions require pointers to FILE structures. Note that
the mode of stream specied must agree with the mode of the open le. The mode parameters are
identical to those specied for fopen( ), except that modes beginning with w do not cause trunca-
tion of the le.
The mode parameter controls the access allowed to the stream. It can have one of the following
values:
r Opens the le for reading.
w Creates a new le for writing, or opens a le to zero length. (Unlike the fopen()
function, the le is not truncated under the fdopen( ) function.)
a Appends (opens a le for writing at the end of the le, or creates a le for writ-
ing).
r+ Opens a le for update (reading and writing).
w+ Truncates or creates a le for update. (Unlike the fopen() function, the le is not
truncated under the fdopen() function.)
a+ Appends (opens a le for update, writing at the end of the le, or creates a le for
writing).
When you open a le for update, you can perform both input and output operations on the result-
ing stream. However, an output operation cannot be directly followed by an input operation
without an intervening fush() function call or a le positioning operation (fseek(), fsetpos(),or
rewind() function). Also, an input operation cannot be directly followed by an output operation
without an intervening ush or le positioning operation, unless the input operation encounters
the end of the le.
When you open a le for append (that is, when the mode parameter is a or a+), it is impossible to
overwrite information already in the le. You can use the fseek() function to reposition the le
pointer to any position in the le, but when output is written to the le, the current le pointer is
527192-005 Hewlett-Packard Company 27