xref: /freebsd/lib/libc/gen/dup3.3 (revision 7b22b8da2fd95d94f795fdf7fc737dedb59051da)
1*7b22b8daSJilles Tjoelker.\" Copyright (c) 2013 Jilles Tjoelker
2*7b22b8daSJilles Tjoelker.\" All rights reserved.
35219e2caSJilles Tjoelker.\"
45219e2caSJilles Tjoelker.\" Redistribution and use in source and binary forms, with or without
55219e2caSJilles Tjoelker.\" modification, are permitted provided that the following conditions
65219e2caSJilles Tjoelker.\" are met:
75219e2caSJilles Tjoelker.\" 1. Redistributions of source code must retain the above copyright
85219e2caSJilles Tjoelker.\"    notice, this list of conditions and the following disclaimer.
95219e2caSJilles Tjoelker.\" 2. Redistributions in binary form must reproduce the above copyright
105219e2caSJilles Tjoelker.\"    notice, this list of conditions and the following disclaimer in the
115219e2caSJilles Tjoelker.\"    documentation and/or other materials provided with the distribution.
125219e2caSJilles Tjoelker.\"
13*7b22b8daSJilles Tjoelker.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
145219e2caSJilles Tjoelker.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155219e2caSJilles Tjoelker.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16*7b22b8daSJilles Tjoelker.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
175219e2caSJilles Tjoelker.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
185219e2caSJilles Tjoelker.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
195219e2caSJilles Tjoelker.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
205219e2caSJilles Tjoelker.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
215219e2caSJilles Tjoelker.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
225219e2caSJilles Tjoelker.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
235219e2caSJilles Tjoelker.\" SUCH DAMAGE.
245219e2caSJilles Tjoelker.\"
255219e2caSJilles Tjoelker.\" $FreeBSD$
265219e2caSJilles Tjoelker.\"
275219e2caSJilles Tjoelker.Dd August 16, 2013
285219e2caSJilles Tjoelker.Dt DUP3 3
295219e2caSJilles Tjoelker.Os
305219e2caSJilles Tjoelker.Sh NAME
315219e2caSJilles Tjoelker.Nm dup3
325219e2caSJilles Tjoelker.Nd duplicate an existing file descriptor
335219e2caSJilles Tjoelker.Sh LIBRARY
345219e2caSJilles Tjoelker.Lb libc
355219e2caSJilles Tjoelker.Sh SYNOPSIS
365219e2caSJilles Tjoelker.In fcntl.h
375219e2caSJilles Tjoelker.In unistd.h
385219e2caSJilles Tjoelker.Ft int
395219e2caSJilles Tjoelker.Fn dup3 "int oldd" "int newd" "int flags"
405219e2caSJilles Tjoelker.Sh DESCRIPTION
415219e2caSJilles TjoelkerThe
425219e2caSJilles Tjoelker.Fn dup3
435219e2caSJilles Tjoelkerfunction
445219e2caSJilles Tjoelkerduplicates an existing object descriptor
455219e2caSJilles Tjoelkerwhile allowing the value of the new descriptor to be specified.
465219e2caSJilles Tjoelker.Pp
475219e2caSJilles TjoelkerThe close-on-exec flag on the new file descriptor is determined by the
485219e2caSJilles Tjoelker.Dv O_CLOEXEC
495219e2caSJilles Tjoelkerbit in
505219e2caSJilles Tjoelker.Fa flags .
515219e2caSJilles Tjoelker.Pp
525219e2caSJilles TjoelkerIf
535219e2caSJilles Tjoelker.Fa oldd
545219e2caSJilles Tjoelker\*(Ne
555219e2caSJilles Tjoelker.Fa newd
565219e2caSJilles Tjoelkerand
575219e2caSJilles Tjoelker.Fa flags
585219e2caSJilles Tjoelker== 0,
595219e2caSJilles Tjoelkerthe behavior is identical to
605219e2caSJilles Tjoelker.Li dup2(oldd, newd) .
615219e2caSJilles Tjoelker.Pp
625219e2caSJilles TjoelkerIf
635219e2caSJilles Tjoelker.Fa oldd
645219e2caSJilles Tjoelker==
655219e2caSJilles Tjoelker.Fa newd ,
665219e2caSJilles Tjoelkerthen
675219e2caSJilles Tjoelker.Fn dup3
685219e2caSJilles Tjoelkerfails, unlike
695219e2caSJilles Tjoelker.Xr dup2 2 .
705219e2caSJilles Tjoelker.Sh RETURN VALUES
715219e2caSJilles TjoelkerThe value -1 is returned if an error occurs.
725219e2caSJilles TjoelkerThe external variable
735219e2caSJilles Tjoelker.Va errno
745219e2caSJilles Tjoelkerindicates the cause of the error.
755219e2caSJilles Tjoelker.Sh ERRORS
765219e2caSJilles TjoelkerThe
775219e2caSJilles Tjoelker.Fn dup3
785219e2caSJilles Tjoelkerfunction fails if:
795219e2caSJilles Tjoelker.Bl -tag -width Er
805219e2caSJilles Tjoelker.It Bq Er EBADF
815219e2caSJilles TjoelkerThe
825219e2caSJilles Tjoelker.Fa oldd
835219e2caSJilles Tjoelkerargument is not a valid active descriptor or the
845219e2caSJilles Tjoelker.Fa newd
855219e2caSJilles Tjoelkerargument is negative or exceeds the maximum allowable descriptor number
865219e2caSJilles Tjoelker.It Bq Er EINVAL
875219e2caSJilles TjoelkerThe
885219e2caSJilles Tjoelker.Fa oldd
895219e2caSJilles Tjoelkerargument is equal to the
905219e2caSJilles Tjoelker.Fa newd
915219e2caSJilles Tjoelkerargument.
925219e2caSJilles Tjoelker.It Bq Er EINVAL
935219e2caSJilles TjoelkerThe
945219e2caSJilles Tjoelker.Fa flags
955219e2caSJilles Tjoelkerargument has bits set other than
965219e2caSJilles Tjoelker.Dv O_CLOEXEC .
975219e2caSJilles Tjoelker.El
985219e2caSJilles Tjoelker.Sh SEE ALSO
995219e2caSJilles Tjoelker.Xr accept 2 ,
1005219e2caSJilles Tjoelker.Xr close 2 ,
1015219e2caSJilles Tjoelker.Xr dup2 2 ,
1025219e2caSJilles Tjoelker.Xr fcntl 2 ,
1035219e2caSJilles Tjoelker.Xr getdtablesize 2 ,
1045219e2caSJilles Tjoelker.Xr open 2 ,
1055219e2caSJilles Tjoelker.Xr pipe 2 ,
1065219e2caSJilles Tjoelker.Xr socket 2 ,
1075219e2caSJilles Tjoelker.Xr socketpair 2
1085219e2caSJilles Tjoelker.Sh STANDARDS
1095219e2caSJilles TjoelkerThe
1105219e2caSJilles Tjoelker.Fn dup3
1115219e2caSJilles Tjoelkerfunction does not conform to any standard.
1125219e2caSJilles Tjoelker.Sh HISTORY
1135219e2caSJilles TjoelkerThe
1145219e2caSJilles Tjoelker.Fn dup3
1155219e2caSJilles Tjoelkerfunction appeared in
1165219e2caSJilles Tjoelker.Fx 10.0 .
117