]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/gen/dup3.3
zfs: merge openzfs/zfs@233d34e47
[FreeBSD/FreeBSD.git] / lib / libc / gen / dup3.3
1 .\" Copyright (c) 2013 Jilles Tjoelker
2 .\" All rights reserved.
3 .\"
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
6 .\" are met:
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\"    notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\"    notice, this list of conditions and the following disclaimer in the
11 .\"    documentation and/or other materials provided with the distribution.
12 .\"
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 .\" SUCH DAMAGE.
24 .\"
25 .Dd August 16, 2013
26 .Dt DUP3 3
27 .Os
28 .Sh NAME
29 .Nm dup3
30 .Nd duplicate an existing file descriptor
31 .Sh LIBRARY
32 .Lb libc
33 .Sh SYNOPSIS
34 .In fcntl.h
35 .In unistd.h
36 .Ft int
37 .Fn dup3 "int oldd" "int newd" "int flags"
38 .Sh DESCRIPTION
39 The
40 .Fn dup3
41 function
42 duplicates an existing object descriptor
43 while allowing the value of the new descriptor to be specified.
44 .Pp
45 The close-on-exec flag on the new file descriptor is determined by the
46 .Dv O_CLOEXEC
47 bit in
48 .Fa flags .
49 .Pp
50 If
51 .Fa oldd
52 \*(Ne
53 .Fa newd
54 and
55 .Fa flags
56 == 0,
57 the behavior is identical to
58 .Li dup2(oldd, newd) .
59 .Pp
60 If
61 .Fa oldd
62 ==
63 .Fa newd ,
64 then
65 .Fn dup3
66 fails, unlike
67 .Xr dup2 2 .
68 .Sh RETURN VALUES
69 The value -1 is returned if an error occurs.
70 The external variable
71 .Va errno
72 indicates the cause of the error.
73 .Sh ERRORS
74 The
75 .Fn dup3
76 function fails if:
77 .Bl -tag -width Er
78 .It Bq Er EBADF
79 The
80 .Fa oldd
81 argument is not a valid active descriptor or the
82 .Fa newd
83 argument is negative or exceeds the maximum allowable descriptor number
84 .It Bq Er EINVAL
85 The
86 .Fa oldd
87 argument is equal to the
88 .Fa newd
89 argument.
90 .It Bq Er EINVAL
91 The
92 .Fa flags
93 argument has bits set other than
94 .Dv O_CLOEXEC .
95 .El
96 .Sh SEE ALSO
97 .Xr accept 2 ,
98 .Xr close 2 ,
99 .Xr dup2 2 ,
100 .Xr fcntl 2 ,
101 .Xr getdtablesize 2 ,
102 .Xr open 2 ,
103 .Xr pipe 2 ,
104 .Xr socket 2 ,
105 .Xr socketpair 2
106 .Sh STANDARDS
107 The
108 .Fn dup3
109 function does not conform to any standard.
110 .Sh HISTORY
111 The
112 .Fn dup3
113 function appeared in
114 .Fx 10.0 .