TEXT   94

dup.txt

Guest on 1st August 2021 05:57:43 PM

  1. NAME
  2.        dup, dup2 - duplicate a file descriptor
  3.  
  4.  
  5.  
  6. SYNOPSIS
  7.        #include <unistd.h>
  8.  
  9.        int dup(int oldfd);
  10.        int dup2(int oldfd, int newfd);
  11.  
  12.  
  13.  
  14. DESCRIPTION
  15.        dup and dup2 create a copy of the file descriptor oldfd.
  16.  
  17.        The  old  and new descriptors may be used interchangeably.
  18.        They share locks, file position pointers  and  flags;  for
  19.        example,  if  the file position is modified by using lseek
  20.        on one of the descriptors, the position  is  also  changed
  21.        for the other.
  22.  
  23.        The  two  descriptors do not share the close-on-exec flag,
  24.        however.
  25.  
  26.        dup uses the lowest-numbered unused descriptor for the new
  27.        descriptor.
  28.  
  29.        dup2 makes newfd be the copy of oldfd, closing newfd first
  30.        if necessary.
  31.  
  32.  
  33.  
  34. RETURN VALUE
  35.        dup and dup2 return the new descriptor, or -1 if an  error
  36.        occurred (in which case, errno is set appropriately).
  37.  
  38.  
  39.  
  40. ERRORS
  41.        EBADF  oldfd  isn't  an  open file descriptor, or newfd is
  42.               out of the allowed range for file descriptors.
  43.  
  44.        EMFILE The process already has the maximum number of  file
  45.               descriptors open and tried to open a new one.
  46.  
  47.  
  48.  
  49. WARNING
  50.        The  error  returned by dup2 is different to that returned
  51.        by fcntl(...,F_DUPFD,...)  when newfd is out of range.  On
  52.        some  systems  dup2  also  sometimes  returns  EINVAL like
  53.        F_DUPFD.
  54.  
  55.  
  56.  
  57. CONFORMING TO
  58.        SVID, AT&T, POSIX, X/OPEN, BSD 4.3
  59.  
  60.  
  61.  
  62. SEE ALSO
  63.         fcntl (2), open (2), close (2).

Raw Paste


Login or Register to edit or fork this paste. It's free.