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