HP C/iX Library Reference Manual (30026-90004)

Chapter 5 143
HP C/iX Library Function Descriptions
fdopen
fdopen
Opens a stream on a file descriptor.
Syntax
#include <stdio.h>
FILE *fdopen (int
fildes
, const char
*type
);
Parameters
fildes
An open file descriptor.
type
A pointer to a character string containing a new access mode. Following
are valid strings and their meanings:
r Open or create file for reading.
w Open or create file for writing.
a Open or create file in append mode. All writes are at
end-of-file.
r+ Open or create file for update (reading and writing).
w+ Open or create file for update.
a+ Open or create file for append update (read anywhere, but
all writes are at end-of-file).
Return Values
x A pointer to an open stream.
NULL An error occurred. There may be too many open files, or the arguments
may have been incorrectly defined.
Description
The fdopen function associates a stream with an open file descriptor. File descriptors are
obtained from the open or dup functions; however, streams are the required form of file
reference for many of the standard I/O library functions. The type of stream must agree
with the mode of the open file.
Opening a file in read mode fails if the file does not exist or cannot be read.
When a file is opened for update, both input and output may be done on the resulting
stream. Do not directly follow output with input without an intervening call to fflush()
or to a file positioning function (fseek(), fsetpos(), or rewind()). Do not directly follow
input with output without an intervening call to a file positioning function unless the input
operation encounters end-of-file.
When a file is opened for append, it is impossible to overwrite information already in the