DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

dup2(S)


dup2 -- duplicate an open file descriptor

Syntax

cc . . . -lc

int dup2 (fildes, fildes2)
int fildes, fildes2;

Description

The fildes argument is a file descriptor referring to an open file, and fildes2 is a non-negative integer less than _NFILE. dup2 causes fildes2 to refer to the same file as fildes. If fildes2 already referred to an open file, it is closed first.

The dup2 function fails if one or more of the following is true:


[EBADF]
fildes is not a valid open file descriptor.

[EINTR]
a signal was caught during the dup2() call.

[EMFILE]
_NFILE file descriptors are currently open.

Diagnostics

Upon successful completion a non-negative integer, namely the file descriptor, is returned. Otherwise, a value of -1 is returned, and errno is set to indicate the error.

See also

creat(S), close(S), exec(S), fcntl(S), lockf(S), open(S), pipe(S)

Standards conformance

dup2 is conformant with:

IEEE POSIX Std 1003.1-1990 System Application Program Interface (API) [C Language] (ISO/IEC 9945-1) ;
and NIST FIPS 151-1 .


© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003