C Language and Libraries Help (clang.hlp) (Table of Contents; Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
_dup, _dup2
 Summary Example                         Up Contents Index Back
─────Run-Time Library───────────────────────────────────────────────────────
 
     The _dup and _dup2 functions cause a second file handle to be
     associated with a currently open file. Operations on the file can
     be carried out using either file handle. The type of access
     allowed for the file is unaffected by the creation of a new
     handle.
 
     The _dup function returns the next available file handle for the
     given file. The _dup2 function 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.
 
     Both _dup and _dup2 accept file handles as arguments. If you want
     to pass a stream (FILE *) to either of these functions, use the
     _fileno function. This function associates a stream with a file
     handle. The following example shows how to associate stderr
     (defined as FILE * in STDIO.H) with a handle:
 
          cstderr = _dup( _fileno( stderr ));
 
     Note that in a QuickWin application, you cannot use either _dup or
     _dup2 with _fileno on the stdin, stdout, or stderr streams. You
     can, however, use the combination of the_dup functions and the
     _fileno function on other streams.
 
     Return Value
 
     The _dup function returns a new file handle. The _dup2 function
     returns 0 to indicate success. Both functions return -1 if an
     error occurs and set errno to either EBADF or EMFILE.
                                    -♦-