sys_dup2  [fs/fcntl.c]


Creates a copy of a file descriptor, closing the original file descriptor if necessary. After a successful return the old and new file descriptors may be used interchangeably. They refer to the same open file description (see sys_open) and thus share file offset and file status flags; for example, if the file offset is modified by using sys_lseek on one of the descriptors, the offset is also changed for the other.

Arguments

eax 63
ebx File descriptor to copy.
ecx File descriptor which should receive the copy of old descriptor.

Return values

If the system call succeeds the return value is the new file descriptor.
If the system call fails the return value is one of the following errno values:

-EBADF ebx isn't an open file descriptor.
-EBUSY Race condition occurred with.
-EINTR The sys_dup2 call was interrupted by a signal.
-EMFILE The process already has the maximum number of file descriptors open and tried to open a new one.

Remarks

The two descriptors do not share file descriptor flags (the close-on-exec flag). The close-on-exec flag (FD_CLOEXEC; see sys_fcntl) for the duplicate descriptor is off.

Compatibility

n/a