Bell 32V development
[unix-history] / usr / man / man2 / dup.2
CommitLineData
cb67878b
TL
1.TH DUP 2
2.SH NAME
3dup, dup2 \- duplicate an open file descriptor
4.SH SYNOPSIS
5.B dup(fildes)
6.br
7.B int fildes;
8.PP
9.B dup2(fildes, fildes2)
10.br
11.B int fildes, fildes2;
12.SH DESCRIPTION
13Given
14a file descriptor returned from
15an
16.I open,
17.I pipe,
18or
19.I creat
20call,
21.I dup
22allocates another file descriptor
23synonymous
24with
25the original.
26The new file descriptor is returned.
27.PP
28In the second form of the call,
29.I fildes
30is a file descriptor referring to an open file, and
31.I fildes2
32is a non-negative integer less than the maximum value
33allowed for file descriptors (approximately 19).
34.I Dup2
35causes
36.I fildes2
37to refer to the same file as
38.I fildes.
39If
40.I fildes2
41already referred to an open file, it is closed first.
42.SH "SEE ALSO"
43creat(2), open(2), close(2), pipe(2)
44.SH DIAGNOSTICS
45The value \-1 is returned if:
46the given file descriptor is invalid;
47there are already too many open files.
48.SH "ASSEMBLER (PDP-11)"
49(dup = 41.)
50.br
51(file descriptor in r0)
52.br
53(new file descriptor in r1)
54.br
55.B sys dup
56.br
57(file descriptor in r0)
58.PP
59The
60.I dup2
61entry is implemented by adding 0100 to
62.I fildes.