HP 3000 Manuals

fdopen [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Library Reference Manual

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 file.  The fseek function may be used to
reposition the file pointer to any position in the file, but when output
is written to the file, the current file pointer is disregarded.  All
output is written at the end of the file, and the file pointer is
repositioned at the end of the output.  When opening a binary file, the
file position indicator may, in some cases, be positioned beyond the last
data written because of blank or null padding.

When opened, a stream is fully buffered only if it can be determined not
to refer to an interactive device.  The error and end-of-file indicators
for a stream are cleared.

See Also 

open(), dup(), close(), POSIX.1 8.1



MPE/iX 5.0 Documentation