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);
handle
handle1
handle2
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.
Dup
: Returns the next available file descriptor for the file.Dup2
: Returns 0 to indicate success.
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 |