Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <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.
    Either file handle can then be used to carry out operations on the
    file because both handles use the same file pointer.

       Returns:     The next available file handle. 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 the new and old handles to refer to the same
                    file.

   -------------------------------- 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");
           }


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

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