DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 

dup2(S)


dup2 -- duplicate an open file descriptor

Synopsis

   #include <unistd.h>
   

int dup2(int fildes, int fildes2);

Description

fildes is a file descriptor referring to an open file, and fildes2 is a non-negative integer less than the maximum number of open files available. dup2 causes fildes2 to refer to the same file as fildes. If fildes2 already referred to an open file, not fildes, it is closed first. If fildes2 refers to fildes, or if fildes is not a valid open file descriptor, fildes2 will not be closed first.

Return values

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.

Errors

dup2 will fail if one or more of the following are true:

EBADF
fildes is not a valid open file descriptor.

EBADF
fildes2 is negative or greater than or equal to the maximum number of open files available.

EINTR
a signal was caught during the dup2 call.

EMFILE
The maximum number of file descriptors are currently open.

References

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


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 - 01 June 2005