1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2001
4 * 07/2001 Ported by Wayne Boyer
5 * 01/2002 Removed EMFILE test - Paul Larson
6 */
7 /*\
8 * [Description]
9 *
10 * Negative tests for dup2() with bad fd (EBADF).
11 *
12 * - First fd argument is less than 0
13 * - First fd argument is getdtablesize()
14 * - Second fd argument is less than 0
15 * - Second fd argument is getdtablesize()
16 *
17 */
18
19 #include <errno.h>
20 #include <unistd.h>
21 #include "tst_test.h"
22
23 static int maxfd, mystdout;
24 static int goodfd = 5;
25 static int badfd = -1;
26
27 static struct tcase {
28 int *ofd;
29 int *nfd;
30 } tcases[] = {
31 {&badfd, &goodfd},
32 {&maxfd, &goodfd},
33 {&mystdout, &badfd},
34 {&mystdout, &maxfd},
35 };
36
setup(void)37 static void setup(void)
38 {
39 /* get some test specific values */
40 maxfd = getdtablesize();
41 }
42
run(unsigned int i)43 static void run(unsigned int i)
44 {
45 struct tcase *tc = tcases + i;
46
47 TST_EXP_FAIL2(dup2(*tc->ofd, *tc->nfd), EBADF,
48 "dup2(%d, %d)", *tc->ofd, *tc->nfd);
49 }
50
51 static struct tst_test test = {
52 .tcnt = ARRAY_SIZE(tcases),
53 .test = run,
54 .setup = setup,
55 };
56