Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
Copyright (c) 2003, Sun Microsystems, Inc. All Rights Reserved.
Copyright 1989 AT&T
Copyright 2024 Oxide Computer Company
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 dup2(int fildes, int fildes2);
int dup3(int fildes, int fildes2, int flags);
The dup2() function is equivalent to fcntl(fildes, F_DUP2FD, fildes2). The returned file descriptor will have neither the close-on-exec (FD_CLOEXEC) or close-on-fork (FD_CLOFORK) flags set on it, regardless of what is set on fildes.
The dup3() function works similarly to the dup2() function with two exceptions. If fildes and fildes2 point to the same file descriptor, -1 is returned and errno set to EINVAL. The flags argument allows for control of the returned file descriptor's flags. Valid values are the bitwise-inclusive-OR of: O_CLOEXEC
The returned file descriptor will have the close-on-exec flag, FD_CLOEXEC set on it. The file descriptor will be automatically closed when the process calls the exec(2) family of functions.
The returned file descriptor will have the close-on-fork flag, FD_CLOFORK set on it. The file descriptor will be automatically closed in any child processes created with the fork(2) family of functions. It will remain open in the parent.
The fildes argument is not a valid open file descriptor.
The fildes2 argument is negative or is not less than the current resource limit returned by getrlimit(RLIMIT_NOFILE, .\|.\|.).
A signal was caught during the dup2() call.
The process has too many open files. See fcntl(2).
Additionally, the dup3() function will fail if: EINVAL
flags has a value other than 0 or the bitwise-inclusive-OR of O_CLOEXEC and O_CLOFORK. fildes and fildes2 point to the same file descriptor.
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Standard |
MT-Level Async-Signal-Safe |