Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    int dup( int handle );

Description:
    The dup function duplicates the file handle given by the argument
    handle.  The new file handle refers to the same open file handle as the
    original file handle, and shares any locks.  The new file handle is
    identical to the original in that it references the same file or device,
    it has the same open mode (read and/or write) and it will have file
    position identical to the original.  Changing the position with one
    handle will result in a changed position in the other.

Returns:
    If successful, the new file handle is returned to be used with the other
    functions which operate on the file.  Otherwise, -1 is returned and
     errno is set to indicate the error.

Errors:
    When an error has occurred,  errno contains a value indicating the type
    of error that has been detected.

    EBADF
        The argument handle is not a valid open file handle.

    EMFILE
        The number of file handles would exceed {OPEN_MAX}.


See Also:
    chsize, close, creat, dup2, eof, exec Functions Functions, filelength, fileno,
    fstat, isatty, lseek, open, read, setmode, sopen, stat, tell, write,
    umask

Example:
    #include <fcntl.h>
    #include <io.h>

    void main()
      {
        int handle, dup_handle;

        handle = open( "file",
                    O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
                    S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
        if( handle != -1 ) {
          dup_handle = dup( handle );
          if( dup_handle != -1 ) {

            /* process file */

            close( dup_handle );
          }
          close( handle );
        }
      }

Classification:
    POSIX 1003.1

Systems:
    All

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson