'\" te .\" Copyright 1989 AT&T Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved .\" 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 DUP 2 "Dec 28, 1996" .SH NAME dup \- duplicate an open file descriptor .SH SYNOPSIS .LP .nf #include \fBint\fR \fBdup\fR(\fBint\fR \fIfildes\fR); .fi .SH DESCRIPTION .sp .LP The \fBdup()\fR function returns a new file descriptor having the following in common with the original open file descriptor \fIfildes\fR: .RS +4 .TP .ie t \(bu .el o same open file (or pipe) .RE .RS +4 .TP .ie t \(bu .el o same file pointer (that is, both file descriptors share one file pointer) .RE .RS +4 .TP .ie t \(bu .el o same access mode (read, write or read/write). .RE .sp .LP The new file descriptor is set to remain open across \fIexec\fR functions (see \fBfcntl\fR(2)). .sp .LP The file descriptor returned is the lowest one available. .sp .LP The \fBdup(\fR\fIfildes\fR\fB)\fR function call is equivalent to: .sp .LP \fBfcntl(\fR\fIfildes\fR\fB, F_DUPFD, 0)\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 \fBdup()\fR function will fail if: .sp .ne 2 .na \fB\fBEBADF\fR\fR .ad .RS 11n The \fIfildes\fR argument is not a valid open file descriptor. .RE .sp .ne 2 .na \fB\fBEINTR\fR\fR .ad .RS 11n A signal was caught during the execution of the \fBdup()\fR function. .RE .sp .ne 2 .na \fB\fBEMFILE\fR\fR .ad .RS 11n The process has too many open files (see \fBgetrlimit\fR(2)). .RE .sp .ne 2 .na \fB\fBENOLINK\fR\fR .ad .RS 11n The \fIfildes\fR argument is on a remote machine and the link to that machine is no longer active. .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), \fBdup2\fR(3C), \fBlockf\fR(3C), \fBattributes\fR(5), \fBstandards\fR(5)