view usr/src/man/man3c/dup2.3c @ 14022:19e11862653b

3713 Implement accept4() 3714 Implement pipe2() 3715 Implement dup3() 3716 Implement mkostemp() and mkostemps() 3719 so_socketpair syscall should preserve FD_CLOEXEC flag Reviewed by: Dan McDonald <danmcd@nexenta.com> Reviewed by: Robert Mustacchi <rm@joyent.com> Approved by: Garrett D'Amore <garrett@damore.org>
author Theo Schlossnagle <jesus@omniti.com>
date Thu, 11 Apr 2013 04:50:36 +0000
parents 5b2854ecc12d
children
line wrap: on
line source

'\" te
.\" Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
.\" 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 "Apr 19, 2013"
.SH NAME
dup2, dup3 \- 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

.LP
.nf
\fBint\fR \fBdup3\fR(\fBint\fR \fIfildes\fR, \fBint\fR \fIfildes2\fR, \dBint\fR \fIflags\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).
.sp
.LP
Ths \fBdup3()\fR function works similarly to the \fBdup2()\fR function with
two exceptions.  If \fIfildes\fR and \fIfildes2\fR point to the same file
descriptor, -1 is returned and errno set to \fBEINVAL\fR.  If \fIflags\fR
is \fBO_CLOEXEC\fR, then \fIfiledes2\fB will have the \fBFD_CLOEXEC\fR flag
set causing the file descriptor to be closed during any future call of
\fBexec\fR(2).
.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 and \fBdup3()\fR functions will fail if:
.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
The \fIfildes\fR argument is not a valid open file descriptor.
.RE

.sp
.ne 2
.na
\fB\fBEBADF\fR\fR
.ad
.RS 10n
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
.na
\fB\fBEINTR\fR\fR
.ad
.RS 10n
A signal was caught during the \fBdup2()\fR call.
.RE

.sp
.ne 2
.na
\fB\fBEMFILE\fR\fR
.ad
.RS 10n
The process has too many open files.  See  \fBfcntl\fR(2).
.RE

.sp
.LP
Additionally, the \fBdup3()\fR function will fail if:
.sp
.ne 2
.na
\fB\fBEINVAL\fR\fR
.ad
.RS 10n
\fIflags\fR has a value other than 0 or \fBO_CLOEXEC\fR or \fIfildes\fR and \fIfildes2\fB point to the same file descriptor.
.RE

.SH ATTRIBUTES
.sp
.LP
See \fBattributes\fR(5) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Standard
_
MT-Level	Async-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)