xref: /aosp_15_r20/external/ltp/testcases/kernel/syscalls/pathconf/pathconf01.c (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
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, 2000-2023
5  * Authors: William Roske, Dave Fenner
6  */
7 
8 /*\
9  * [Description]
10  *
11  * Check the basic functionality of the pathconf(2) system call.
12  */
13 
14 #include <stdlib.h>
15 #include "tst_test.h"
16 
17 #define NAME_DESC(x) .value = x, .name = #x
18 
19 static char *path;
20 
21 static struct tcase {
22 	int value;
23 	char *name;
24 } tcases[] = {
25 	{NAME_DESC(_PC_LINK_MAX)},
26 	{NAME_DESC(_PC_MAX_CANON)},
27 	{NAME_DESC(_PC_MAX_INPUT)},
28 	{NAME_DESC(_PC_NAME_MAX)},
29 	{NAME_DESC(_PC_PATH_MAX)},
30 	{NAME_DESC(_PC_PIPE_BUF)},
31 	{NAME_DESC(_PC_CHOWN_RESTRICTED)},
32 	{NAME_DESC(_PC_NO_TRUNC)},
33 	{NAME_DESC(_PC_VDISABLE)},
34 	{NAME_DESC(_PC_SYNC_IO)},
35 	{NAME_DESC(_PC_ASYNC_IO)},
36 	{NAME_DESC(_PC_PRIO_IO)},
37 	{NAME_DESC(_PC_FILESIZEBITS)},
38 	{NAME_DESC(_PC_REC_INCR_XFER_SIZE)},
39 	{NAME_DESC(_PC_REC_MAX_XFER_SIZE)},
40 	{NAME_DESC(_PC_REC_MIN_XFER_SIZE)},
41 	{NAME_DESC(_PC_REC_XFER_ALIGN)},
42 };
43 
verify_pathconf(unsigned int i)44 static void verify_pathconf(unsigned int i)
45 {
46 	struct tcase *tc = &tcases[i];
47 
48 	path = tst_get_tmpdir();
49 
50 	TEST(pathconf(path, tc->value));
51 
52 	if (TST_RET == -1 && errno != 0)
53 		tst_res(TFAIL, "pathconf Failed, errno = %d", TST_ERR);
54 	else
55 		tst_res(TPASS, "pathconf(%s, %s)", path, tc->name);
56 }
57 
cleanup(void)58 static void cleanup(void)
59 {
60 	free(path);
61 }
62 
63 static struct tst_test test = {
64 	.needs_tmpdir = 1,
65 	.test = verify_pathconf,
66 	.tcnt = ARRAY_SIZE(tcases),
67 	.cleanup = cleanup,
68 };
69