nightly: remove unused BINARCHIVE
[unleashed.git] / share / man / man2 / dup.2
blobdcb3bf0b2068a766cfc5bc1e5892bd42053a1725
1 '\" te
2 .\"  Copyright 1989 AT&T  Copyright (c) 1997, Sun Microsystems, Inc.  All Rights Reserved
3 .\" 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.
4 .\" 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.
5 .\" 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]
6 .TH DUP 2 "Dec 28, 1996"
7 .SH NAME
8 dup \- duplicate an open file descriptor
9 .SH SYNOPSIS
10 .LP
11 .nf
12 #include <unistd.h>
14 \fBint\fR \fBdup\fR(\fBint\fR \fIfildes\fR);
15 .fi
17 .SH DESCRIPTION
18 .sp
19 .LP
20 The \fBdup()\fR function returns a new file descriptor having the following in
21 common with the original open file descriptor \fIfildes\fR:
22 .RS +4
23 .TP
24 .ie t \(bu
25 .el o
26 same open file (or pipe)
27 .RE
28 .RS +4
29 .TP
30 .ie t \(bu
31 .el o
32 same file pointer (that is, both file descriptors share one file pointer)
33 .RE
34 .RS +4
35 .TP
36 .ie t \(bu
37 .el o
38 same access mode (read, write or read/write).
39 .RE
40 .sp
41 .LP
42 The new file descriptor is set to remain open across \fIexec\fR functions (see
43 \fBfcntl\fR(2)).
44 .sp
45 .LP
46 The file descriptor returned is the lowest one available.
47 .sp
48 .LP
49 The \fBdup(\fR\fIfildes\fR\fB)\fR function call is equivalent to:
50 .sp
51 .LP
52 \fBfcntl(\fR\fIfildes\fR\fB, F_DUPFD, 0)\fR
53 .SH RETURN VALUES
54 .sp
55 .LP
56 Upon successful completion, a non-negative integer representing the file
57 descriptor is returned. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is
58 set to indicate the error.
59 .SH ERRORS
60 .sp
61 .LP
62 The \fBdup()\fR function will fail if:
63 .sp
64 .ne 2
65 .na
66 \fB\fBEBADF\fR\fR
67 .ad
68 .RS 11n
69 The \fIfildes\fR argument is not a valid open file descriptor.
70 .RE
72 .sp
73 .ne 2
74 .na
75 \fB\fBEINTR\fR\fR
76 .ad
77 .RS 11n
78 A signal was caught during the execution of the \fBdup()\fR function.
79 .RE
81 .sp
82 .ne 2
83 .na
84 \fB\fBEMFILE\fR\fR
85 .ad
86 .RS 11n
87 The process has too many open files (see \fBgetrlimit\fR(2)).
88 .RE
90 .sp
91 .ne 2
92 .na
93 \fB\fBENOLINK\fR\fR
94 .ad
95 .RS 11n
96 The \fIfildes\fR argument is on a remote machine and the link to that machine
97 is no longer active.
98 .RE
100 .SH ATTRIBUTES
103 See \fBattributes\fR(5) for descriptions of the following attributes:
108 box;
109 c | c
110 l | l .
111 ATTRIBUTE TYPE  ATTRIBUTE VALUE
113 Interface Stability     Standard
115 MT-Level        Async-Signal-Safe
118 .SH SEE ALSO
121 \fBclose\fR(2), \fBcreat\fR(2), \fBexec\fR(2), \fBfcntl\fR(2),
122 \fBgetrlimit\fR(2), \fBopen\fR(2), \fBpipe\fR(2), \fBdup2\fR(3C),
123 \fBlockf\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)