xref: /freebsd/lib/libc/gen/dup3.3 (revision fa9896e082a1046ff4fbc75fcba4d18d1f2efc19)
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.Dd August 16, 2013
265219e2caSJilles Tjoelker.Dt DUP3 3
275219e2caSJilles Tjoelker.Os
285219e2caSJilles Tjoelker.Sh NAME
295219e2caSJilles Tjoelker.Nm dup3
305219e2caSJilles Tjoelker.Nd duplicate an existing file descriptor
315219e2caSJilles Tjoelker.Sh LIBRARY
325219e2caSJilles Tjoelker.Lb libc
335219e2caSJilles Tjoelker.Sh SYNOPSIS
345219e2caSJilles Tjoelker.In fcntl.h
355219e2caSJilles Tjoelker.In unistd.h
365219e2caSJilles Tjoelker.Ft int
375219e2caSJilles Tjoelker.Fn dup3 "int oldd" "int newd" "int flags"
385219e2caSJilles Tjoelker.Sh DESCRIPTION
395219e2caSJilles TjoelkerThe
405219e2caSJilles Tjoelker.Fn dup3
415219e2caSJilles Tjoelkerfunction
425219e2caSJilles Tjoelkerduplicates an existing object descriptor
435219e2caSJilles Tjoelkerwhile allowing the value of the new descriptor to be specified.
445219e2caSJilles Tjoelker.Pp
455219e2caSJilles TjoelkerThe close-on-exec flag on the new file descriptor is determined by the
465219e2caSJilles Tjoelker.Dv O_CLOEXEC
475219e2caSJilles Tjoelkerbit in
485219e2caSJilles Tjoelker.Fa flags .
495219e2caSJilles Tjoelker.Pp
505219e2caSJilles TjoelkerIf
515219e2caSJilles Tjoelker.Fa oldd
525219e2caSJilles Tjoelker\*(Ne
535219e2caSJilles Tjoelker.Fa newd
545219e2caSJilles Tjoelkerand
555219e2caSJilles Tjoelker.Fa flags
565219e2caSJilles Tjoelker== 0,
575219e2caSJilles Tjoelkerthe behavior is identical to
585219e2caSJilles Tjoelker.Li dup2(oldd, newd) .
595219e2caSJilles Tjoelker.Pp
605219e2caSJilles TjoelkerIf
615219e2caSJilles Tjoelker.Fa oldd
625219e2caSJilles Tjoelker==
635219e2caSJilles Tjoelker.Fa newd ,
645219e2caSJilles Tjoelkerthen
655219e2caSJilles Tjoelker.Fn dup3
665219e2caSJilles Tjoelkerfails, unlike
675219e2caSJilles Tjoelker.Xr dup2 2 .
685219e2caSJilles Tjoelker.Sh RETURN VALUES
695219e2caSJilles TjoelkerThe value -1 is returned if an error occurs.
705219e2caSJilles TjoelkerThe external variable
715219e2caSJilles Tjoelker.Va errno
725219e2caSJilles Tjoelkerindicates the cause of the error.
735219e2caSJilles Tjoelker.Sh ERRORS
745219e2caSJilles TjoelkerThe
755219e2caSJilles Tjoelker.Fn dup3
765219e2caSJilles Tjoelkerfunction fails if:
775219e2caSJilles Tjoelker.Bl -tag -width Er
785219e2caSJilles Tjoelker.It Bq Er EBADF
795219e2caSJilles TjoelkerThe
805219e2caSJilles Tjoelker.Fa oldd
815219e2caSJilles Tjoelkerargument is not a valid active descriptor or the
825219e2caSJilles Tjoelker.Fa newd
835219e2caSJilles Tjoelkerargument is negative or exceeds the maximum allowable descriptor number
845219e2caSJilles Tjoelker.It Bq Er EINVAL
855219e2caSJilles TjoelkerThe
865219e2caSJilles Tjoelker.Fa oldd
875219e2caSJilles Tjoelkerargument is equal to the
885219e2caSJilles Tjoelker.Fa newd
895219e2caSJilles Tjoelkerargument.
905219e2caSJilles Tjoelker.It Bq Er EINVAL
915219e2caSJilles TjoelkerThe
925219e2caSJilles Tjoelker.Fa flags
935219e2caSJilles Tjoelkerargument has bits set other than
945219e2caSJilles Tjoelker.Dv O_CLOEXEC .
955219e2caSJilles Tjoelker.El
965219e2caSJilles Tjoelker.Sh SEE ALSO
975219e2caSJilles Tjoelker.Xr accept 2 ,
985219e2caSJilles Tjoelker.Xr close 2 ,
995219e2caSJilles Tjoelker.Xr dup2 2 ,
1005219e2caSJilles Tjoelker.Xr fcntl 2 ,
1015219e2caSJilles Tjoelker.Xr getdtablesize 2 ,
1025219e2caSJilles Tjoelker.Xr open 2 ,
1035219e2caSJilles Tjoelker.Xr pipe 2 ,
1045219e2caSJilles Tjoelker.Xr socket 2 ,
1055219e2caSJilles Tjoelker.Xr socketpair 2
1065219e2caSJilles Tjoelker.Sh STANDARDS
1075219e2caSJilles TjoelkerThe
1085219e2caSJilles Tjoelker.Fn dup3
1095219e2caSJilles Tjoelkerfunction does not conform to any standard.
1105219e2caSJilles Tjoelker.Sh HISTORY
1115219e2caSJilles TjoelkerThe
1125219e2caSJilles Tjoelker.Fn dup3
1135219e2caSJilles Tjoelkerfunction appeared in
1145219e2caSJilles Tjoelker.Fx 10.0 .
115