1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) International Business Machines Corp., 2002
4 * 11/20/2002 Port to LTP <[email protected]>
5 * 06/30/2001 Port to Linux <[email protected]>
6 * Copyright (C) 2022 SUSE LLC Andrea Cervesato <[email protected]>
7 * Copyright (c) 2022 Petr Vorel <[email protected]>
8 */
9
10 /*\
11 * [Description]
12 *
13 * Test confstr(3) 700 (X/Open 7) functionality -- POSIX 2008.
14 */
15
16 #define _XOPEN_SOURCE 700
17
18 #include <stdlib.h>
19 #include <unistd.h>
20
21 #include "tst_test.h"
22
23 #define PAIR(name) {_CS_ ## name, #name}
24
25 static struct test_case_t {
26 int value;
27 char *name;
28 } test_cases[] = {
29 PAIR(PATH),
30 PAIR(GNU_LIBC_VERSION),
31 PAIR(GNU_LIBPTHREAD_VERSION),
32 PAIR(POSIX_V7_ILP32_OFF32_CFLAGS),
33 PAIR(POSIX_V7_ILP32_OFF32_LDFLAGS),
34 PAIR(POSIX_V7_ILP32_OFF32_LIBS),
35 PAIR(POSIX_V7_ILP32_OFFBIG_CFLAGS),
36 PAIR(POSIX_V7_ILP32_OFFBIG_LDFLAGS),
37 PAIR(POSIX_V7_ILP32_OFFBIG_LIBS),
38 PAIR(POSIX_V7_LP64_OFF64_CFLAGS),
39 PAIR(POSIX_V7_LP64_OFF64_LDFLAGS),
40 PAIR(POSIX_V7_LP64_OFF64_LIBS),
41 PAIR(POSIX_V7_LPBIG_OFFBIG_CFLAGS),
42 PAIR(POSIX_V7_LPBIG_OFFBIG_LDFLAGS),
43 PAIR(POSIX_V7_LPBIG_OFFBIG_LIBS),
44 #ifdef _CS_POSIX_V7_THREADS_CFLAGS
45 PAIR(POSIX_V7_THREADS_CFLAGS),
46 #endif
47 #ifdef _CS_POSIX_V7_THREADS_LDFLAGS
48 PAIR(POSIX_V7_THREADS_LDFLAGS),
49 #endif
50 PAIR(POSIX_V7_WIDTH_RESTRICTED_ENVS),
51 #ifdef _CS_V7_ENV
52 PAIR(V7_ENV),
53 #endif
54 };
55
run(unsigned int i)56 static void run(unsigned int i)
57 {
58 char *buf;
59 int len;
60
61 TST_EXP_POSITIVE(confstr(test_cases[i].value, NULL, (size_t)0));
62
63 if (!TST_RET)
64 return;
65
66 len = TST_RET;
67 buf = SAFE_MALLOC(len);
68
69 TEST(confstr(test_cases[i].value, buf, len));
70
71 if (buf[len - 1] != '\0') {
72 tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name,
73 tst_strerrno(TST_ERR));
74 } else {
75 tst_res(TPASS, "confstr %s = '%s'", test_cases[i].name, buf);
76 }
77
78 free(buf);
79 }
80
81 static struct tst_test test = {
82 .test = run,
83 .tcnt = ARRAY_SIZE(test_cases),
84 };
85