Skip to content

Commit 391f69a

Browse files
Avineshpevik
authored andcommitted
dup05.c: use TST_EXP_FD() macro and make check fixes
+ update copyright + use SAFE_OPEN() and SAFE_CLOSE() Reviewed-by: Petr Vorel <[email protected]> Signed-off-by: Avinesh Kumar <[email protected]> Signed-off-by: Petr Vorel <[email protected]>
1 parent 911ff30 commit 391f69a

File tree

1 file changed

+17
-29
lines changed
  • testcases/kernel/syscalls/dup

1 file changed

+17
-29
lines changed

testcases/kernel/syscalls/dup/dup05.c

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,43 @@
11
// SPDX-License-Identifier: GPL-2.0-only
22
/*
33
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4-
*
54
* 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
5+
* Copyright (c) 2012-2023 SUSE LLC
66
*/
77

88
/*\
9-
* [DESCRIPTION]
9+
* [Description]
1010
*
11-
* Basic test for dup(2) of a named pipe descriptor
11+
* Basic test for dup(2) of a named pipe descriptor.
1212
*/
13-
#include <stdio.h>
13+
1414
#include "tst_test.h"
1515

16-
char Fname[255];
17-
int fd;
16+
#define FNAME "dupfile"
17+
18+
static int fd = -1;
1819

1920
static void run(void)
2021
{
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-
}
22+
TST_EXP_FD(dup(fd), "dup(%d)", fd);
23+
SAFE_CLOSE(TST_RET);
3124
}
3225

33-
void setup(void)
26+
static void setup(void)
3427
{
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");
28+
SAFE_MKFIFO(FNAME, 0777);
29+
fd = SAFE_OPEN(FNAME, O_RDWR, 0700);
4130
}
4231

43-
void cleanup(void)
32+
static void cleanup(void)
4433
{
4534
if (fd != -1)
46-
if (close(fd) == -1)
47-
tst_res(TWARN | TERRNO, "close failed");
35+
SAFE_CLOSE(fd);
4836
}
4937

5038
static struct tst_test test = {
51-
.test_all = run,
52-
.setup = setup,
53-
.cleanup = cleanup,
39+
.test_all = run,
40+
.setup = setup,
41+
.cleanup = cleanup,
5442
.needs_tmpdir = 1,
5543
};

0 commit comments

Comments
 (0)