]> git.lizzy.rs Git - plan9front.git/blob - sys/man/2/dup
audiohda: fix syntax error
[plan9front.git] / sys / man / 2 / dup
1 .TH DUP 2
2 .SH NAME
3 dup \- duplicate an open file descriptor
4 .SH SYNOPSIS
5 .B #include <u.h>
6 .br
7 .B #include <libc.h>
8 .PP
9 .B
10 int dup(int oldfd, int newfd)
11 .SH DESCRIPTION
12 Given a file descriptor,
13 .IR oldfd ,
14 referring to an open file,
15 .I dup
16 returns a new file descriptor referring to the same file.
17 .PP
18 If
19 .I newfd
20 is \-1 the system chooses the lowest available file descriptor.
21 Otherwise,
22 .I dup
23 will use
24 .I newfd
25 for the new file descriptor
26 (closing any old file associated with
27 .IR newfd ).
28 File descriptors are allocated dynamically,
29 so to prevent unwarranted growth of the file descriptor table,
30 .I dup
31 requires that
32 .I newfd
33 be no greater than 20 more than the highest file descriptor ever used by
34 the program.
35 .PP
36 .I Dup
37 does not copy the per file descriptor
38 .B OCEXEC
39 flag,
40 meaning that
41 .I newfd
42 will not be closed on
43 .IR exec(2)
44 syscall,
45 when
46 .I oldfd
47 had been previously opend with it.
48 .SH SOURCE
49 .B /sys/src/libc/9syscall
50 .SH SEE ALSO
51 .IR intro (2),
52 .IR dup (3)
53 .SH DIAGNOSTICS
54 Sets
55 .IR errstr .