◄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. -♦-