FAT | RFS | XFS | ZFS

dup()

PROTOTYPE

#include <posix.h>

int dup(int fid);

DESCRIPTION

dup() allocates the lowest numbered free file descriptor and associates it with the same open file referenced by fid. The new descriptor must be freed, such as by close(), when no longer needed.

"dup(fid)" is equivalent to "fcntl(fid, F_DUPFD, 0);".

If successful, dup() returns a new file descriptor. Otherwise, it sets errno and returns -1.

ERROR CODES

EBADF fid is not the descriptor of a file open in read-only mode.
EMFILE No file control block is free. FOPEN_MAX files are currently open.

EXAMPLE

  /*-------------------------------------------------------------------*/
  /* Use duplicate file ID for stdin to read.                          */
  /*-------------------------------------------------------------------*/
  fid = dup(stdin);
  read(fid, buf, BUF_SIZE);
  close(fid);