home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mntdoc01.zoo / mintdoc / cat3 / dup.3 < prev    next >
Encoding:
Text File  |  1993-03-03  |  2.1 KB  |  67 lines

  1.  
  2.  
  3.  
  4. DUP(3)              MINTLIB LIBRARY FUNCTIONS              DUP(3)
  5.  
  6.  
  7. N✓NA✓AM✓ME✓E
  8.        dup, dup2 - duplicate a file descriptor
  9.  
  10. S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
  11.        #include <unistd.h>
  12.  
  13.        int dup(int fd);
  14.  
  15.        int dup2(int fd1, int fd2);
  16.  
  17. D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
  18.        dup  duplicates  an existing file descriptor. The argument
  19.        fd is a small  non-negative  integer  index  in  the  per-
  20.        process  descriptor  table. The new descriptor returned by
  21.        the call is the lowest numbered  descriptor  that  is  not
  22.        currently in use by the process.
  23.  
  24.        With  dup2,  fd2  specifies  the  desired value of the new
  25.        descriptor.  If descriptor fd2 is already in  use,  it  is
  26.        first deallocted as if it were closed by close.
  27.  
  28.        The  new  descriptor  has the following in common with the
  29.        original:
  30.  
  31.        - It refers to the same object that the old
  32.          descriptor referred to.
  33.  
  34.        - It uses the same seek pointer as the old descriptor
  35.          (that is, both file descriptors share one seek pointer).
  36.  
  37.        - It has the same access mode (read, write or read/write)
  38.          as the old descriptor.
  39.  
  40.        Thus  if  fd2  and fd1 are duplicate references to an open
  41.        file, read, write, and lseek calls all move a single  seek
  42.        pointer  into  the file, and append mode is shared between
  43.        the references. If a separate seek pointer into  the  file
  44.        is  desired, a different object reference to the file must
  45.        be obtained by issuing an additional open call.
  46.  
  47. R✓RE✓ET✓TU✓UR✓RN✓N V✓VA✓AL✓LU✓UE✓ES✓S
  48.        dup and dup2 return a new descriptor on success.  On fail-
  49.        ure, they return -1 and set errno to indicate the error.
  50.  
  51. S✓SE✓EE✓E A✓AL✓LS✓SO✓O
  52.        c✓cl✓lo✓os✓se✓e(✓(3✓3)✓),✓,  f✓fc✓cn✓nt✓tl✓l(✓(3✓3)✓),✓,  l✓ls✓se✓ee✓ek✓k(✓(3✓3)✓),✓, o✓op✓pe✓en✓n(✓(3✓3)✓),✓, p✓pi✓ip✓pe✓e(✓(3✓3)✓),✓, r✓re✓ea✓ad✓d(✓(3✓3)✓),✓,
  53.        w✓wr✓ri✓it✓te✓e(✓(3✓3)✓),✓, F✓Fd✓du✓up✓p(✓(2✓2)✓),✓, F✓Ff✓fo✓or✓rc✓ce✓e(✓(2✓2)✓),✓, F✓Fc✓cn✓nt✓tl✓l(✓(2✓2)✓)
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64. MiNT docs 0.1              3 March 1993                         1
  65.  
  66.  
  67.