1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
2f08c3bdfSopenharmony_ci/*
3f08c3bdfSopenharmony_ci * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
4f08c3bdfSopenharmony_ci * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
5f08c3bdfSopenharmony_ci * Copyright (c) 2012-2023 SUSE LLC
6f08c3bdfSopenharmony_ci */
7f08c3bdfSopenharmony_ci
8f08c3bdfSopenharmony_ci/*\
9f08c3bdfSopenharmony_ci * [Description]
10f08c3bdfSopenharmony_ci *
11f08c3bdfSopenharmony_ci * Basic test for dup(2) of a named pipe descriptor.
12f08c3bdfSopenharmony_ci */
13f08c3bdfSopenharmony_ci
14f08c3bdfSopenharmony_ci#include "tst_test.h"
15f08c3bdfSopenharmony_ci
16f08c3bdfSopenharmony_ci#define FNAME "dupfile"
17f08c3bdfSopenharmony_ci
18f08c3bdfSopenharmony_cistatic int fd = -1;
19f08c3bdfSopenharmony_ci
20f08c3bdfSopenharmony_cistatic void run(void)
21f08c3bdfSopenharmony_ci{
22f08c3bdfSopenharmony_ci	TST_EXP_FD(dup(fd), "dup(%d)", fd);
23f08c3bdfSopenharmony_ci	SAFE_CLOSE(TST_RET);
24f08c3bdfSopenharmony_ci}
25f08c3bdfSopenharmony_ci
26f08c3bdfSopenharmony_cistatic void setup(void)
27f08c3bdfSopenharmony_ci{
28f08c3bdfSopenharmony_ci	SAFE_MKFIFO(FNAME, 0777);
29f08c3bdfSopenharmony_ci	fd = SAFE_OPEN(FNAME, O_RDWR, 0700);
30f08c3bdfSopenharmony_ci}
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_cistatic void cleanup(void)
33f08c3bdfSopenharmony_ci{
34f08c3bdfSopenharmony_ci	if (fd != -1)
35f08c3bdfSopenharmony_ci		SAFE_CLOSE(fd);
36f08c3bdfSopenharmony_ci}
37f08c3bdfSopenharmony_ci
38f08c3bdfSopenharmony_cistatic struct tst_test test = {
39f08c3bdfSopenharmony_ci	.test_all = run,
40f08c3bdfSopenharmony_ci	.setup = setup,
41f08c3bdfSopenharmony_ci	.cleanup = cleanup,
42f08c3bdfSopenharmony_ci	.needs_tmpdir = 1,
43f08c3bdfSopenharmony_ci};
44