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