2 .\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
3 .\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
4 .\" Copyright 1989 AT&T
5 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
6 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
7 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
8 .TH DUP2 3C "Apr 19, 2013"
10 dup2, dup3 \- duplicate an open file descriptor
16 \fBint\fR \fBdup2\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR);
21 \fBint\fR \fBdup3\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR, \dBint\fR \fIflags\fR);
27 The \fBdup2()\fR function causes the file descriptor \fIfildes2\fR to refer to
28 the same file as \fIfildes\fR. The \fIfildes\fR argument is a file descriptor
29 referring to an open file, and \fIfildes2\fR is a non-negative integer less
30 than the current value for the maximum number of open file descriptors allowed
31 the calling process. See \fBgetrlimit\fR(2). If \fIfildes2\fR already refers
32 to an open file, not \fIfildes\fR, it is closed first. If \fIfildes2\fR refers
33 to \fIfildes\fR, or if \fIfildes\fR is not a valid open file descriptor,
34 \fIfildes2\fR will not be closed first.
37 The \fBdup2()\fR function is equivalent to \fBfcntl\fR(\fIfildes\fR,
38 \fBF_DUP2FD\fR, \fIfildes2\fR).
41 Ths \fBdup3()\fR function works similarly to the \fBdup2()\fR function with
42 two exceptions. If \fIfildes\fR and \fIfildes2\fR point to the same file
43 descriptor, -1 is returned and errno set to \fBEINVAL\fR. If \fIflags\fR
44 is \fBO_CLOEXEC\fR, then \fIfiledes2\fB will have the \fBFD_CLOEXEC\fR flag
45 set causing the file descriptor to be closed during any future call of
50 Upon successful completion a non-negative integer representing the file
51 descriptor is returned. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is
52 set to indicate the error.
56 The \fBdup2()\fR and \fBdup3()\fR functions will fail if:
63 The \fIfildes\fR argument is not a valid open file descriptor.
72 The \fIfildes2\fR argument is negative or is not less than the current resource
73 limit returned by \fBgetrlimit(RLIMIT_NOFILE, .\|.\|.)\fR.
82 A signal was caught during the \fBdup2()\fR call.
91 The process has too many open files. See \fBfcntl\fR(2).
96 Additionally, the \fBdup3()\fR function will fail if:
103 \fIflags\fR has a value other than 0 or \fBO_CLOEXEC\fR or \fIfildes\fR and \fIfildes2\fB point to the same file descriptor.
109 See \fBattributes\fR(5) for descriptions of the following attributes:
117 ATTRIBUTE TYPE ATTRIBUTE VALUE
119 Interface Stability Standard
121 MT-Level Async-Signal-Safe
127 \fBclose\fR(2), \fBcreat\fR(2), \fBexec\fR(2), \fBfcntl\fR(2),
128 \fBgetrlimit\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBattributes\fR(5),