1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2013 Fujitsu Ltd.
4 * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Test for various EINVAL error.
11 *
12 * - oldfd is equal to newfd without using O_CLOEXEC flag
13 * - oldfd is equal to newfd with using O_CLOEXEC flag
14 * - flags contain an invalid value
15 */
16
17 #define _GNU_SOURCE
18 #define INVALID_FLAG -1
19
20 #include <errno.h>
21 #include "tst_test.h"
22 #include "tst_safe_macros.h"
23
24 static int old_fd = 3;
25 static int new_fd = 5;
26
27 static struct tcase {
28 int *oldfd;
29 int *newfd;
30 int flags;
31 } tcases[] = {
32 {&old_fd, &old_fd, O_CLOEXEC},
33 {&old_fd, &old_fd, 0},
34 {&old_fd, &new_fd, INVALID_FLAG}
35 };
36
run(unsigned int i)37 static void run(unsigned int i)
38 {
39 struct tcase *tc = tcases + i;
40
41 TST_EXP_FAIL2(dup3(*tc->oldfd, *tc->newfd, tc->flags), EINVAL,
42 "dup3(%d, %d, %d)", *tc->oldfd, *tc->newfd, tc->flags);
43 }
44
45 static struct tst_test test = {
46 .tcnt = ARRAY_SIZE(tcases),
47 .test = run,
48 };
49