dup2

Forces the file handle to reference the same open file as the handle parameter (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 dup2  (  
     int   handle,   
     int   handle2);
  

Parameters

handle
(IN) Specifies the file handle to be duplicated.
handle2
(IN) Specifies the file handle to be forced to reference the same file as the handle parameter.

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 handle parameter must be a handle to a file that is already open. If handle2 references a file that is already open, that file is closed before handle2 is forced to reference the file for handle.

See Also

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