dup

Returns a file handle that refers to the same open file as handle (supported only for NetWare 4.x and above)

Local Servers:nonblocking
Remote Servers:nonblocking
Classification:POSIX
Platform:NLM
Service:Operating System I/O

Syntax

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

Parameters

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

Return Values

When an error occurs, a value of -1 is returned. Otherwise, the return value is a nonnegative integer that is the file handle.

If an error occurs, errno can be set to:

Decimal

Constant

Description

4

EBADF

Bad file number

11

EMFILE

Too many open files

Remarks

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

NOTE:For an example of how to reverse the effect of redirecting stdin, see the example for fdopen.

See Also

close, creat, dup2, eof, fdopen, filelength, fileno, fstat, ftell, isatty, lseek, open, read, sopen, write