1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
'\" te
.\" Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
.\" Copyright 1989 AT&T
.\" 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.
.\" 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.
.\" 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]
.TH dup2 3C "19 Dec 2003" "SunOS 5.11" "Standard C Library Functions"
.SH NAME
dup2 \- duplicate an open file descriptor
.SH SYNOPSIS
.LP
.nf
#include <unistd.h>
\fBint\fR \fBdup2\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR);
.fi
.SH DESCRIPTION
.sp
.LP
The \fBdup2()\fR function causes the file descriptor \fIfildes2\fR to refer to
the same file as \fIfildes\fR. The \fIfildes\fR argument is a file descriptor
referring to an open file, and \fIfildes2\fR is a non-negative integer less
than the current value for the maximum number of open file descriptors allowed
the calling process. See \fBgetrlimit\fR(2). If \fIfildes2\fR already refers
to an open file, not \fIfildes\fR, it is closed first. If \fIfildes2\fR refers
to \fIfildes\fR, or if \fIfildes\fR is not a valid open file descriptor,
\fIfildes2\fR will not be closed first.
.sp
.LP
The \fBdup2()\fR function is equivalent to \fBfcntl\fR(\fIfildes\fR,
\fBF_DUP2FD\fR, \fIfildes2\fR).
.SH RETURN VALUES
.sp
.LP
Upon successful completion a non-negative integer representing the file
descriptor is returned. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is
set to indicate the error.
.SH ERRORS
.sp
.LP
The \fBdup2()\fR function will fail if:
.sp
.ne 2
.mk
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
.rt
The \fIfildes\fR argument is not a valid open file descriptor.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
.rt
The \fIfildes2\fR argument is negative or is not less than the current resource
limit returned by \fBgetrlimit(RLIMIT_NOFILE, .\|.\|.)\fR.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEINTR\fR\fR
.ad
.RS 10n
.rt
A signal was caught during the \fBdup2()\fR call.
.RE
.sp
.ne 2
.mk
.na
\fB\fBEMFILE\fR\fR
.ad
.RS 10n
.rt
The process has too many open files. See \fBfcntl\fR(2).
.RE
.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp
.sp
.TS
tab() box;
cw(2.75i) |cw(2.75i)
lw(2.75i) |lw(2.75i)
.
ATTRIBUTE TYPEATTRIBUTE VALUE
_
Interface StabilityStandard
_
MT-LevelAsync-Signal-Safe
.TE
.SH SEE ALSO
.sp
.LP
\fBclose\fR(2), \fBcreat\fR(2), \fBexec\fR(2), \fBfcntl\fR(2),
\fBgetrlimit\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBattributes\fR(5),
\fBstandards\fR(5)
|