dup()                    Create Second Handle for Open File
 
 #include <io.h>                         Required for declarations only
 
 int        dup(handle);
 int        handle;                      Handle referring to open file
 
    dup() causes a second file handle to be associated with an open file.
    Either file handle can be used to carry out operations on the file,
    since all handles associated with a given file use the same file
    pointer.
 
    Returns:    The next available file handle for the given file, or -1
                if there is an error.  On error, ERRNO is set to one of
                the following:
 
                    EBADF         Invalid file handle
                    EMFILE        Too many files open
 
      Notes:    File access is unaffected by the creation of a new file
                handle.
 
                dup() returns the next available handle. dup2()  forces a
                given handle to refer to the same file as 'handle'.
 
  -------------------------------- Example ---------------------------------
 
    These statements create another file handle for an open file.
 
          #include <io.h>
          #include <stdlib.h>
 
          int hndl;
 
          main()
          {
                hndl = dup(1);       /* handle 1 is stdout */
                if (hndl == -1)
                   perror("error getting second handle");
           }

Seealso:



This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster