INtime SDK Help
dup, dup2

Dup creates a second file descriptor for an open file in the running thread's file descriptor table and dup2 reassigns a file descriptor in the table.

#include <io.h>

int dup (int handle);

int dup2 (int handle1, int handle2);


Descriptor referring to an open file.
Descriptor referring to an open file.
Any file descriptor value.


Operations on the file can be carried out using either the old or new file descriptor. The type of access allowed for the file is unaffected by the creation of a new file descriptor.

Dup2 forces handle2 to refer to the same file as handle1. If handle2 is associated with an open file at the time of the call, that file is closed.

The C library keeps track of the number of duplications on a file connection. The original connection will remain valid until the last duplication is closed or deleted.

Return Values

Dup: Returns the next available file descriptor for the file.
Dup2: Returns 0 to indicate success.
Both functions return -1 if an error occurs and set errno to one of these values:
EBADF Invalid file descriptor.
EMFILE No more file descriptors available (too many open files).


Versions Defined in Include Link to
INtime 3.0 intime/rt/include/io.h io.h clib.lib

See Also

close, creat