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]
#include <unistd.h> int dup(int fildes);
The dup() function returns a new file descriptor having the following in common with the original open file descriptor fildes:
same open file (or pipe)
same file pointer (that is, both file descriptors share one file pointer)
The new file descriptor is set to remain open across exec functions (see fcntl(2)).
The file descriptor returned is the lowest one available.
The dup(fildes) function call is equivalent to:
fcntl(fildes, F_DUPFD, 0)
Upon successful completion, a non-negative integer representing the file descriptor is returned. Otherwise, -1 is returned and errno is set to indicate the error.
The dup() function will fail if: EBADF
The fildes argument is not a valid open file descriptor.
A signal was caught during the execution of the dup() function.
The process has too many open files (see getrlimit(2)).
The fildes argument is on a remote machine and the link to that machine is no longer active.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Standard |
MT-Level Async-Signal-Safe |
close(2), creat(2), exec(2), fcntl(2), getrlimit(2), open(2), pipe(2), dup2(3C), lockf(3C), attributes(5), standards(5)