Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- 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 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");
           }

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

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