• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  *
6  * 03/30/1992 AUTHOR: William Roske CO-PILOT: Dave Fenner
7  *
8  */
9 
10 #include "tst_test.h"
11 
12 static int fd;
13 
verify_dup(void)14 static void verify_dup(void)
15 {
16 	TEST(dup(fd));
17 
18 	if (TST_RET < -1) {
19 		tst_res(TFAIL, "Invalid dup() return value %ld", TST_RET);
20 	} else if (TST_RET == -1) {
21 		tst_res(TFAIL | TTERRNO, "dup(%d) Failed", fd);
22 	} else {
23 		tst_res(TPASS, "dup(%d) returned %ld", fd, TST_RET);
24 		SAFE_CLOSE(TST_RET);
25 	}
26 }
27 
setup(void)28 static void setup(void)
29 {
30 	fd = SAFE_OPEN("dupfile", O_RDWR | O_CREAT, 0700);
31 }
32 
cleanup(void)33 static void cleanup(void)
34 {
35 	if (fd > 0)
36 		SAFE_CLOSE(fd);
37 }
38 
39 static struct tst_test test = {
40 	.test_all = verify_dup,
41 	.setup = setup,
42 	.cleanup = cleanup,
43 	.needs_tmpdir = 1,
44 };
45