Open System Services System Calls Reference Manual (G06.25+, H06.03+)

dup(2) OSS System Calls Reference Manual
NAME
dup - Duplicates an open le descriptor
LIBRARY
G-series native OSS processes: system library
H-series OSS processes: implicit libraries
SYNOPSIS
#include <unistd.h>
int dup(
int ledes);
PARAMETERS
filedes Species an open le descriptor obtained from a successful call to the accept(),
creat(), dup( ), dup2( ), fcntl( ), open(), pipe( ), socket(),orsocketpair() func-
tion.
DESCRIPTION
The dup( ) function returns a new le descriptor for the open le specied by the ledes parame-
ter. This le descriptor:
Is the lowest-numbered available le descriptor
References the same open
Returns the same le pointer as the original le (that is, both le descriptors share one
le pointer if the object is a le)
Returns the same access mode (read, write, or read/write)
Returns the same le status ags (that is, both le descriptors share the same le status
ags)
Clears the close-on-exec ag (FD_CLOEXEC bit) associated with the new le descrip-
tor so that the le remains open across calls to any function in the exec, tdm_exec, and
tdm_spawn sets of functions
NOTES
The dup( ) function provides an alternative interface to the service provided by the fcntl( ) func-
tion by using the F_DUPFD value of the request parameter. The call:
fid = dup( file1 );
is equivalent to:
fid = fcntl( file1, F_DUPFD, 0 );
RETURN VALUES
Upon successful completion, the dup( ) function returns a new le descriptor. If the dup() func-
tion fails, the value -1 is returned, and errno is set to indicate the error.
ERRORS
If any of these conditions occurs, the dup( ) function sets errno to the corresponding value:
[EBADF] The ledes parameter is not a valid open le descriptor.
138 Hewlett-Packard Company 527186-003