Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>dup() create second handle for open file</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 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.
    Because all handles affiliated with a file use the same file pointer,
    either file handle can then be used to carry out operations on the
    file.

    Returns:    The next available file handle for the given file. On
                error, -1 is returned and '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 file handle 1
    ('stdout').

            #include <io.h>
            #include <stdlib.h>

            int hndl;

            main()
            {
                  hndl = dup(1);       /* handle 1 is stdout */
                  if (hndl == -1)
                     perror("error getting second handle");
            }


See Also: close() creat() open() dup2()

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