'\" te .\" Copyright 1989 AT&T Copyright (c) 1997, Sun Microsystems, Inc. All Rights Reserved .TH dup 2 "28 Dec 1996" "SunOS 5.11" "System Calls" .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 .mk .na \fB\fBEBADF\fR\fR .ad .RS 11n .rt The \fIfildes\fR argument is not a valid open file descriptor. .RE .sp .ne 2 .mk .na \fB\fBEINTR\fR\fR .ad .RS 11n .rt A signal was caught during the execution of the \fBdup()\fR function. .RE .sp .ne 2 .mk .na \fB\fBEMFILE\fR\fR .ad .RS 11n .rt The process has too many open files (see \fBgetrlimit\fR(2)). .RE .sp .ne 2 .mk .na \fB\fBENOLINK\fR\fR .ad .RS 11n .rt 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 tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPEATTRIBUTE VALUE _ Interface StabilityCommitted _ MT-LevelAsync-Signal-Safe _ StandardSee \fBstandards\fR(5). .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)