dup

Returns a file descriptor that refers to the same open file as fildes.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <unistd.h> 
   
  int dup (
     int   fildes);
  

Parameters

fildes

(IN) Specifies the file descriptor that is to be duplicated.

Return Values

If successful, returns a nonnegative integer that is the duplicated file descriptor. Otherwise, returns -1 and sets errno to one of the following values:

Decimal

Constant

Description

4

EBADF

The fildes parameter isn't a valid file descriptor.

11

EMFILE

Too many open files.

Remarks

The dup function duplicates a file descriptor by returning a file descriptor that refers to the same open file as the fildes parameter. Because both handles reference the same file, either handle can be used for operations on the file.

See Also