1 /* $OpenBSD: dup3.c,v 1.1.1.1 2018/04/10 23:00:53 bluhm Exp $ */ 2 /* 3 * Copyright (c) 2018 Alexander Bluhm <bluhm@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 #include <err.h> 19 #include <fcntl.h> 20 #include <unistd.h> 21 22 #include "header.h" 23 24 void 25 fdops(int fdpre, int fdpost) 26 { 27 if (dup3(fdpre, 5, O_CLOEXEC) == -1) 28 err(1, "dup3 pre"); 29 if (dup3(fdpost, 6, O_CLOEXEC) == -1) 30 err(1, "dup3 post"); 31 if (dup3(fdpre, 7, O_CLOEXEC) == -1) 32 err(1, "dup3 pepare post overwite"); 33 if (dup3(fdpost, 7, O_CLOEXEC) == -1) 34 err(1, "dup3 post overwrite"); 35 if (dup3(fdpost, 8, O_CLOEXEC) == -1) 36 err(1, "dup3 pepare pre overwrite"); 37 if (dup3(fdpre, 8, O_CLOEXEC) == -1) 38 err(1, "dup3 pre overwite"); 39 if (dup3(fdpre, 9, 0) == -1) 40 err(1, "dup3 pepare pre equal"); 41 if (dup3(9, 9, O_CLOEXEC) != -1) 42 errx(1, "dup3 pre equal succeeded"); 43 if (dup3(fdpost, 10, 0) == -1) 44 err(1, "dup3 pepare post equal"); 45 if (dup3(10, 10, O_CLOEXEC) != -1) 46 errx(1, "dup3 post equal succeeded"); 47 } 48