mirror of https://github.com/mkerrisk/man-pages
Consistent use of terms "open file description",
"file status flags", and "file decriptor flags" Removed mention of lock sharing -- it was not accurate. Minor formatting fixes
This commit is contained in:
parent
e366dbc4fb
commit
0a5a85eb64
42
man2/dup.2
42
man2/dup.2
|
@ -40,27 +40,35 @@ dup, dup2 \- duplicate a file descriptor
|
|||
.BI "int dup2(int " oldfd ", int " newfd );
|
||||
.fi
|
||||
.SH DESCRIPTION
|
||||
.BR dup " and " dup2
|
||||
.BR dup "() and " dup2 ()
|
||||
create a copy of the file descriptor
|
||||
.IR oldfd .
|
||||
|
||||
After successful return of \fBdup\fR or \fBdup2\fR,
|
||||
the old and new descriptors may be used interchangeably. They share
|
||||
locks, file position pointers and flags; for example, if the file
|
||||
position is modified by using
|
||||
.B lseek
|
||||
After a successful return from \fBdup\fR() or \fBdup2\fR(),
|
||||
the old and new file descriptors may be used interchangeably.
|
||||
They refer to the same open file description (see
|
||||
.BR open (2))
|
||||
and thus share file offset and file status flags;
|
||||
for example, if the file offset is modified by using
|
||||
.BR lseek (2)
|
||||
on one of the descriptors, the position is also changed for the other.
|
||||
|
||||
The two descriptors do not share the close-on-exec flag, however.
|
||||
The two descriptors do not share file descriptor flags
|
||||
(the close-on-exec flag).
|
||||
The close-on-exec flag
|
||||
.RB ( FD_CLOEXEC ;
|
||||
see
|
||||
.BR fcntl (2))
|
||||
for the duplicate descriptor is off.
|
||||
|
||||
.B dup
|
||||
.BR dup ()
|
||||
uses the lowest-numbered unused descriptor for the new descriptor.
|
||||
|
||||
.B dup2
|
||||
.BR dup2 ()
|
||||
.RI "makes " newfd " be the copy of " oldfd ", closing " newfd
|
||||
first if necessary.
|
||||
.SH "RETURN VALUE"
|
||||
.BR dup " and " dup2
|
||||
.BR dup "() and " dup2 ()
|
||||
return the new descriptor, or \-1 if an error occurred (in which case,
|
||||
.I errno
|
||||
is set appropriately).
|
||||
|
@ -74,37 +82,37 @@ is out of the allowed range for file descriptors.
|
|||
.TP
|
||||
.B EBUSY
|
||||
(Linux only) This may be returned by
|
||||
.B dup2
|
||||
.BR dup2 ()
|
||||
during a race condition with open() and dup().
|
||||
.TP
|
||||
.B EINTR
|
||||
The
|
||||
.B dup2
|
||||
.BR dup2 ()
|
||||
call was interrupted by a signal.
|
||||
.TP
|
||||
.B EMFILE
|
||||
The process already has the maximum number of file
|
||||
descriptors open and tried to open a new one.
|
||||
.SH WARNING
|
||||
.SH WARNINGS
|
||||
The error returned by
|
||||
.B dup2
|
||||
.BR dup2 ()
|
||||
is different from that returned by
|
||||
.BR fcntl( "..., " F_DUPFD ", ..." )
|
||||
when
|
||||
.I newfd
|
||||
is out of range. On some systems
|
||||
.B dup2
|
||||
.BR dup2 ()
|
||||
also sometimes returns
|
||||
.B EINVAL
|
||||
like
|
||||
.BR F_DUPFD .
|
||||
.SH BUGS
|
||||
|
||||
If
|
||||
.I newfd
|
||||
was open, any errors that would have been reported at
|
||||
.IR close ()
|
||||
time, are lost. A careful programmer will not use
|
||||
.B dup2
|
||||
.BR dup2 ()
|
||||
without closing
|
||||
.I newfd
|
||||
first.
|
||||
|
|
Loading…
Reference in New Issue