Improved english
[unix-history] / usr / src / lib / libc / sys / dup.2
CommitLineData
ff35cc74
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
b5f0627a 5.\" @(#)dup.2 6.2 (Berkeley) %G%
ff35cc74 6.\"
d4d39c08 7.TH DUP 2 ""
ff35cc74
KM
8.UC 4
9.SH NAME
936824e3 10dup, dup2 \- duplicate a descriptor
ff35cc74
KM
11.SH SYNOPSIS
12.nf
936824e3
KM
13.ft B
14newd = dup(oldd)
15int newd, oldd;
ff35cc74 16.PP
936824e3
KM
17.ft B
18dup2(oldd, newd)
19int oldd, newd;
ff35cc74
KM
20.fi
21.SH DESCRIPTION
936824e3
KM
22.I Dup
23duplicates an existing object descriptor.
24The argument \fIoldd\fP is a small non-negative integer index in
25the per-process descriptor table. The value must be less
26than the size of the table, which is returned by
27.IR getdtablesize (2).
b5f0627a
SS
28The new descriptor returned by the call,
29.I newd,
30is the lowest numbered descriptor that is
936824e3 31not currently in use by the process.
ff35cc74 32.PP
936824e3
KM
33The object referenced by the descriptor does not distinguish
34between references using \fIoldd\fP and \fInewd\fP in any way.
35Thus if \fInewd\fP and \fIoldd\fP are duplicate references to an open
36file,
37.IR read (2),
38.IR write (2)
39and
40.IR lseek (2)
41calls all move a single pointer into the file.
42If a separate pointer into the file is desired, a different
43object reference to the file must be obtained by issuing an
44additional
45.IR open (2)
46call.
ff35cc74 47.PP
936824e3
KM
48In the second form of the call, the value of
49.IR newd
50desired is specified. If this descriptor is already
51in use, the descriptor is first deallocated as if a
52.IR close (2)
53call had been done first.
54.SH "RETURN VALUE
55The value \-1 is returned if an error occurs in either call.
56The external variable
57.I errno
58indicates the cause of the error.
59.SH "ERRORS
60.I Dup
61and
ff35cc74 62.I dup2
936824e3
KM
63fail if:
64.TP 15
65[EBADF]
66\fIOldd\fP or
67\fInewd\fP is not a valid active descriptor
68.TP 15
69[EMFILE]
70Too many descriptors are active.
71.SH "SEE ALSO"
72accept(2),
73open(2),
74close(2),
75pipe(2),
76socket(2),
77socketpair(2),
78getdtablesize(2)