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