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