11573Srgrimes/*- 21573Srgrimes * Copyright (c) 2012 Jukka A. Ukkonen 31573Srgrimes * All rights reserved. 41573Srgrimes * 51573Srgrimes * This software was developed by Jukka Ukkonen for FreeBSD. 61573Srgrimes * 71573Srgrimes * Redistribution and use in source and binary forms, with or without 81573Srgrimes * modification, are permitted provided that the following conditions 91573Srgrimes * are met: 101573Srgrimes * 1. Redistributions of source code must retain the above copyright 111573Srgrimes * notice, this list of conditions and the following disclaimer. 121573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 131573Srgrimes * notice, this list of conditions and the following disclaimer in the 141573Srgrimes * documentation and/or other materials provided with the distribution. 151573Srgrimes * 161573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 171573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 181573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 191573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 201573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 211573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 221573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 231573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 241573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 251573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 261573Srgrimes * SUCH DAMAGE. 271573Srgrimes */ 281573Srgrimes 291573Srgrimes#include <sys/cdefs.h> 301573Srgrimes__FBSDID("$FreeBSD$"); 3123658Speter 321573Srgrimes#include "namespace.h" 3390039Sobrien#include <unistd.h> 3490039Sobrien#include <fcntl.h> 351573Srgrimes#include <errno.h> 361573Srgrimes#include "un-namespace.h" 3765632Sphk 381573Srgrimesint 391573Srgrimes__dup3(int oldfd, int newfd, int flags) 40225847Sed{ 411573Srgrimes int how; 4265955Sphk 4348882Sphk if (oldfd == newfd) { 441573Srgrimes errno = EINVAL; 4548882Sphk return (-1); 46116610Sphk } 4748882Sphk 4880552Stmm if (flags & ~O_CLOEXEC) { 4980552Stmm errno = EINVAL; 5048882Sphk return (-1); 51203290Sed } 52203290Sed 53203290Sed how = (flags & O_CLOEXEC) ? F_DUP2FD_CLOEXEC : F_DUP2FD; 54203290Sed 55203290Sed return (_fcntl(oldfd, how, newfd)); 56203290Sed} 57116610Sphk 5865632Sphk__weak_reference(__dup3, dup3); 5965632Sphk__weak_reference(__dup3, _dup3); 60203290Sed