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

Chapter 5 133
HP C/iX Library Function Descriptions
dup
dup
Duplicates an open file descriptor.
Syntax
#include <fcntl.h>
int dup (int
fildes
);
Parameters
fildes
A file descriptor.
Return Values
n
A non-negative integer representing the new file descriptor.
1 An error occurred and errno is set to one of the following values:
EBADF The
fildes
parameter is not a valid open file descriptor.
EMFILE The maximum number of file descriptors are currently
open.
Description
The dup function returns the lowest-numbered available file descriptor. The new file
descriptor returned by dup() refers to the same open file description as
fildes
. The data
in the file is not duplicated; only the file descriptor is duplicated.
Using dup() to create two file descriptors that point to the same file is different from
opening the file twice with open(). With dup(), both file descriptors use the same file table
entry, and the same file offset is used for reads and writes. With open(), multiple file
descriptors and file table entries are created, and multiple file offset variables are used
with reads and writes.
The new file descriptor has the following in common with the original file descriptor:
Both share the same open file description.
Both share the same file position indicator.
Both share the same access mode.
NOTE
If linking with the POSIX/iX library, refer to the description of dup() located
in the MPE/iX Developer's Kit Reference Manual.
See Also
open()