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 Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <io.h>
    int dup( int handle );
    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.

    The _dup function is identical to dup.  Use _dup for ANSI/ISO naming
    conventions.

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.

    Constant     Meaning

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

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


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:
    dup is POSIX 1003.1, _dup is not POSIX

_dup conforms to ANSI/ISO naming conventions

Systems:
     dup - All, Netware

    _dup - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32

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

See Also: chsize dup2

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