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