1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * Copyright (c) Linux Test Project, 2003-2024
5 */
6
7 /*\
8 * [Description]
9 *
10 * Check the basic functionality of the fpathconf(2) system call.
11 */
12
13 #include "tst_test.h"
14
15 static struct tcase {
16 char *name;
17 int value;
18 } test_cases[] = {
19 {"_PC_MAX_CANON", _PC_MAX_CANON},
20 {"_PC_MAX_INPUT", _PC_MAX_INPUT},
21 {"_PC_VDISABLE", _PC_VDISABLE},
22 {"_PC_LINK_MAX", _PC_LINK_MAX},
23 {"_PC_NAME_MAX", _PC_NAME_MAX},
24 {"_PC_PATH_MAX", _PC_PATH_MAX},
25 {"_PC_PIPE_BUF", _PC_PIPE_BUF},
26 {"_PC_CHOWN_RESTRICTED", _PC_CHOWN_RESTRICTED},
27 {"_PC_NO_TRUNC", _PC_NO_TRUNC},
28 };
29
30 static int fd;
31
verify_fpathconf(unsigned int n)32 static void verify_fpathconf(unsigned int n)
33 {
34 struct tcase *tc = &test_cases[n];
35
36 TST_EXP_POSITIVE(fpathconf(fd, tc->value));
37 }
38
setup(void)39 static void setup(void)
40 {
41 fd = SAFE_OPEN("fpafile01", O_RDWR | O_CREAT, 0700);
42 }
43
cleanup(void)44 static void cleanup(void)
45 {
46 if (fd > 0)
47 SAFE_CLOSE(fd);
48 }
49
50 static struct tst_test test = {
51 .needs_tmpdir = 1,
52 .test = verify_fpathconf,
53 .tcnt = ARRAY_SIZE(test_cases),
54 .setup = setup,
55 .cleanup = cleanup,
56 };
57