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 );
|
.BI "int dup2(int " oldfd ", int " newfd );
|
||||||
.fi
|
.fi
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.BR dup " and " dup2
|
.BR dup "() and " dup2 ()
|
||||||
create a copy of the file descriptor
|
create a copy of the file descriptor
|
||||||
.IR oldfd .
|
.IR oldfd .
|
||||||
|
|
||||||
After successful return of \fBdup\fR or \fBdup2\fR,
|
After a successful return from \fBdup\fR() or \fBdup2\fR(),
|
||||||
the old and new descriptors may be used interchangeably. They share
|
the old and new file descriptors may be used interchangeably.
|
||||||
locks, file position pointers and flags; for example, if the file
|
They refer to the same open file description (see
|
||||||
position is modified by using
|
.BR open (2))
|
||||||
.B lseek
|
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.
|
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.
|
uses the lowest-numbered unused descriptor for the new descriptor.
|
||||||
|
|
||||||
.B dup2
|
.BR dup2 ()
|
||||||
.RI "makes " newfd " be the copy of " oldfd ", closing " newfd
|
.RI "makes " newfd " be the copy of " oldfd ", closing " newfd
|
||||||
first if necessary.
|
first if necessary.
|
||||||
.SH "RETURN VALUE"
|
.SH "RETURN VALUE"
|
||||||
.BR dup " and " dup2
|
.BR dup "() and " dup2 ()
|
||||||
return the new descriptor, or \-1 if an error occurred (in which case,
|
return the new descriptor, or \-1 if an error occurred (in which case,
|
||||||
.I errno
|
.I errno
|
||||||
is set appropriately).
|
is set appropriately).
|
||||||
|
@ -74,37 +82,37 @@ is out of the allowed range for file descriptors.
|
||||||
.TP
|
.TP
|
||||||
.B EBUSY
|
.B EBUSY
|
||||||
(Linux only) This may be returned by
|
(Linux only) This may be returned by
|
||||||
.B dup2
|
.BR dup2 ()
|
||||||
during a race condition with open() and dup().
|
during a race condition with open() and dup().
|
||||||
.TP
|
.TP
|
||||||
.B EINTR
|
.B EINTR
|
||||||
The
|
The
|
||||||
.B dup2
|
.BR dup2 ()
|
||||||
call was interrupted by a signal.
|
call was interrupted by a signal.
|
||||||
.TP
|
.TP
|
||||||
.B EMFILE
|
.B EMFILE
|
||||||
The process already has the maximum number of file
|
The process already has the maximum number of file
|
||||||
descriptors open and tried to open a new one.
|
descriptors open and tried to open a new one.
|
||||||
.SH WARNING
|
.SH WARNINGS
|
||||||
The error returned by
|
The error returned by
|
||||||
.B dup2
|
.BR dup2 ()
|
||||||
is different from that returned by
|
is different from that returned by
|
||||||
.BR fcntl( "..., " F_DUPFD ", ..." )
|
.BR fcntl( "..., " F_DUPFD ", ..." )
|
||||||
when
|
when
|
||||||
.I newfd
|
.I newfd
|
||||||
is out of range. On some systems
|
is out of range. On some systems
|
||||||
.B dup2
|
.BR dup2 ()
|
||||||
also sometimes returns
|
also sometimes returns
|
||||||
.B EINVAL
|
.B EINVAL
|
||||||
like
|
like
|
||||||
.BR F_DUPFD .
|
.BR F_DUPFD .
|
||||||
.SH BUGS
|
|
||||||
If
|
If
|
||||||
.I newfd
|
.I newfd
|
||||||
was open, any errors that would have been reported at
|
was open, any errors that would have been reported at
|
||||||
.IR close ()
|
.IR close ()
|
||||||
time, are lost. A careful programmer will not use
|
time, are lost. A careful programmer will not use
|
||||||
.B dup2
|
.BR dup2 ()
|
||||||
without closing
|
without closing
|
||||||
.I newfd
|
.I newfd
|
||||||
first.
|
first.
|
||||||
|
|
Loading…
Reference in New Issue