1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 *
5 * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
6 */
7
8 /*\
9 * [DESCRIPTION]
10 *
11 * Basic test for dup(2) of a named pipe descriptor
12 */
13 #include <stdio.h>
14 #include "tst_test.h"
15
16 char Fname[255];
17 int fd;
18
run(void)19 static void run(void)
20 {
21 TEST(dup(fd));
22
23 if (TST_RET == -1) {
24 tst_res(TFAIL | TTERRNO, "dup failed");
25 } else {
26 tst_res(TPASS, "dup returned %ld",
27 TST_RET);
28
29 SAFE_CLOSE(TST_RET);
30 }
31 }
32
setup(void)33 void setup(void)
34 {
35 fd = -1;
36
37 sprintf(Fname, "dupfile");
38 SAFE_MKFIFO(Fname, 0777);
39 if ((fd = open(Fname, O_RDWR, 0700)) == -1)
40 tst_brk(TBROK, "open failed");
41 }
42
cleanup(void)43 void cleanup(void)
44 {
45 if (fd != -1)
46 if (close(fd) == -1)
47 tst_res(TWARN | TERRNO, "close failed");
48 }
49
50 static struct tst_test test = {
51 .test_all = run,
52 .setup = setup,
53 .cleanup = cleanup,
54 .needs_tmpdir = 1,
55 };
56