1/*	$OpenBSD: confstr.c,v 1.10 2013/03/07 06:00:18 guenther Exp $ */
2/*-
3 * Copyright (c) 1993
4 *	The Regents of the University of California.  All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of the University nor the names of its contributors
15 *    may be used to endorse or promote products derived from this software
16 *    without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31#include <errno.h>
32#include <paths.h>
33#include <string.h>
34#include <unistd.h>
35
36
37static const char v6_width_restricted_envs[] = {
38#ifdef __LP64__
39	"POSIX_V6_LP64_OFF64\n"
40	"POSIX_V6_LPBIG_OFFBIG"
41#else
42	"POSIX_V6_ILP32_OFFBIG"
43#endif
44};
45
46static const char v7_width_restricted_envs[] = {
47#ifdef __LP64__
48	"POSIX_V7_LP64_OFF64\n"
49	"POSIX_V7_LPBIG_OFFBIG"
50#else
51	"POSIX_V7_ILP32_OFFBIG"
52#endif
53};
54
55size_t
56confstr(int name, char *buf, size_t len)
57{
58	switch (name) {
59	case _CS_PATH:
60		return (strlcpy(buf, _PATH_STDPATH, len) + 1);
61
62	/* no configuration-defined value */
63	case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
64	case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
65	case _CS_POSIX_V6_ILP32_OFF32_LIBS:
66	case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
67	case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
68	case _CS_POSIX_V7_ILP32_OFF32_LIBS:
69		return (0);
70
71	/* these are either NULL or empty, depending on the platform */
72	case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
73	case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
74	case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
75	case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
76	case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
77	case _CS_POSIX_V7_ILP32_OFFBIG_LIBS:
78#ifdef __LP64__
79		return (0);
80#else
81		if (len > 0)
82			buf[0] = '\0';
83		return (1);
84#endif
85	case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
86	case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
87	case _CS_POSIX_V6_LP64_OFF64_LIBS:
88	case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
89	case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
90	case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
91	case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
92	case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
93	case _CS_POSIX_V7_LP64_OFF64_LIBS:
94	case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS:
95	case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS:
96	case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS:
97#ifdef __LP64__
98		if (len > 0)
99			buf[0] = '\0';
100		return (1);
101#else
102		return (0);
103#endif
104
105	/* zero length strings */
106	case _CS_POSIX_V7_THREADS_CFLAGS:
107	case _CS_V6_ENV:
108	case _CS_V7_ENV:
109		if (len > 0)
110			buf[0] = '\0';
111		return (1);
112
113	case _CS_POSIX_V7_THREADS_LDFLAGS:
114		return (strlcpy(buf, "-lpthread", len) + 1);
115
116	case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:
117		return (strlcpy(buf, v6_width_restricted_envs, len) + 1);
118
119	case _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS:
120		return (strlcpy(buf, v7_width_restricted_envs, len) + 1);
121
122	default:
123		errno = EINVAL;
124		return (0);
125	}
126	/* NOTREACHED */
127}
128