Open System Services Library Calls Reference Manual (G06.29+, H06.08+, J06.03+)

OSS Library Calls (e - f) fdopen(3)
NAME
fdopen - Associates a stream with a file descriptor
LIBRARY
G-series native Guardian processes: $SYSTEM.SYSnn.ZCRTLSRL
G-series native OSS processes: /G/system/sysnn/zcrtlsrl
H-series and J-series native Guardian processes: $SYSTEM.ZDLLnnn.ZCRTLDLL
32-bit H-series and J-series OSS processes: /G/system/zdllnnn/zcrtldll
64-bit H-series and J-series OSS processes: /G/system/zdllnnn/ycrtldll
SYNOPSIS
#include <stdio.h>
FILE fdopen(
int filedes,
const char mode);
PARAMETERS
mode Points to a character string that controls whether the file is opened for reading
(r), writing (w), or appending (a) and whether the file is opened for updating (+).
filedes Specifies a valid open file descriptor.
DESCRIPTION
The fdopen( ) function associates a stream with a file descriptor obtained from an open( ), dup( ),
creat( ),orpipe( ) function. These functions open files, 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 specified must agree with the mode of the open file. The mode parameters are
identical to those specified for fopen( ), except that modes beginning with w do not cause trunca-
tion of the file.
The mode parameter controls the access allowed to the stream. It can have one of the following
values:
r Opens the file for reading.
w Creates a new file for writing, or opens a file to zero length. (Unlike the fopen( )
function, the file is not truncated under the fdopen( ) function.)
a Appends (opens a file for writing at the end of the file, or creates a file for writ-
ing).
r+ Opens a file for update (reading and writing).
w+ Truncates or creates a file for update. (Unlike the fopen( ) function, the file is not
truncated under the fdopen( ) function.)
a+ Appends (opens a file for update, writing at the end of the file, or creates a file for
writing).
When you open a file 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 file positioning operation (fseek(), fsetpos( ),or
rewind( ) function). Also, an input operation cannot be directly followed by an output operation
without an intervening 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
527187-017 Hewlett-Packard Company 245