remove csh(1)
[unleashed.git] / share / man / man3c / dup2.3c
blobf889752c3dc5c4fb245ca4ec974a32db1fbdd208
1 '\" te
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"
9 .SH NAME
10 dup2, dup3 \- duplicate an open file descriptor
11 .SH SYNOPSIS
12 .LP
13 .nf
14 #include <unistd.h>
16 \fBint\fR \fBdup2\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR);
17 .fi
19 .LP
20 .nf
21 \fBint\fR \fBdup3\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR, \dBint\fR \fIflags\fR);
22 .fi
24 .SH DESCRIPTION
25 .sp
26 .LP
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.
35 .sp
36 .LP
37 The \fBdup2()\fR function is equivalent to  \fBfcntl\fR(\fIfildes\fR,
38 \fBF_DUP2FD\fR, \fIfildes2\fR).
39 .sp
40 .LP
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\fR will have the \fBFD_CLOEXEC\fR flag
45 set causing the file descriptor to be closed during any future call of
46 \fBexec\fR(2).
47 .SH RETURN VALUES
48 .sp
49 .LP
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.
53 .SH ERRORS
54 .sp
55 .LP
56 The \fBdup2()\fR and \fBdup3()\fR functions will fail if:
57 .sp
58 .ne 2
59 .na
60 \fB\fBEBADF\fR\fR
61 .ad
62 .RS 10n
63 The \fIfildes\fR argument is not a valid open file descriptor.
64 .RE
66 .sp
67 .ne 2
68 .na
69 \fB\fBEBADF\fR\fR
70 .ad
71 .RS 10n
72 The \fIfildes2\fR argument is negative or is not less than the current resource
73 limit returned by \fBgetrlimit(RLIMIT_NOFILE, .\|.\|.)\fR.
74 .RE
76 .sp
77 .ne 2
78 .na
79 \fB\fBEINTR\fR\fR
80 .ad
81 .RS 10n
82 A signal was caught during the \fBdup2()\fR call.
83 .RE
85 .sp
86 .ne 2
87 .na
88 \fB\fBEMFILE\fR\fR
89 .ad
90 .RS 10n
91 The process has too many open files.  See  \fBfcntl\fR(2).
92 .RE
94 .sp
95 .LP
96 Additionally, the \fBdup3()\fR function will fail if:
97 .sp
98 .ne 2
99 .na
100 \fB\fBEINVAL\fR\fR
102 .RS 10n
103 \fIflags\fR has a value other than 0 or \fBO_CLOEXEC\fR or \fIfildes\fR and
104 \fIfildes2\fR point to the same file descriptor.
107 .SH ATTRIBUTES
110 See \fBattributes\fR(5) for descriptions of the following attributes:
115 box;
116 c | c
117 l | l .
118 ATTRIBUTE TYPE  ATTRIBUTE VALUE
120 Interface Stability     Standard
122 MT-Level        Async-Signal-Safe
125 .SH SEE ALSO
128 \fBclose\fR(2), \fBcreat\fR(2), \fBexec\fR(2), \fBfcntl\fR(2),
129 \fBgetrlimit\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBattributes\fR(5),
130 \fBstandards\fR(5)