xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/dup/dup02.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4  * Copyright (c) 2020 SUSE LLC
5  * 03/30/1992 AUTHOR: Richard Logan CO-PILOT: William Roske
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Verify that dup(2) syscall fails with errno EBADF when called with
12  * invalid value for oldfd argument.
13  */
14 
15 #include "tst_test.h"
16 
17 static struct tcase {
18 	int fd;
19 	int exp_err;
20 } tcases[] = {
21 	{-1, EBADF},
22 	{1500, EBADF},
23 };
24 
run(unsigned int n)25 static void run(unsigned int n)
26 {
27 	struct tcase *tc = &tcases[n];
28 
29 	TST_EXP_FAIL2(dup(tc->fd), tc->exp_err, "dup(%d)", tc->fd);
30 
31 	if (TST_RET != -1)
32 		SAFE_CLOSE(TST_RET);
33 }
34 
35 static struct tst_test test = {
36 	.test = run,
37 	.tcnt = ARRAY_SIZE(tcases),
38 };
39