confstr.c revision 114443
1254225Speter/*-
2254225Speter * Copyright (c) 1993
3254225Speter *	The Regents of the University of California.  All rights reserved.
4254225Speter *
5254225Speter * Redistribution and use in source and binary forms, with or without
6254225Speter * modification, are permitted provided that the following conditions
7254225Speter * are met:
8254225Speter * 1. Redistributions of source code must retain the above copyright
9254225Speter *    notice, this list of conditions and the following disclaimer.
10254225Speter * 2. Redistributions in binary form must reproduce the above copyright
11254225Speter *    notice, this list of conditions and the following disclaimer in the
12254225Speter *    documentation and/or other materials provided with the distribution.
13254225Speter * 3. All advertising materials mentioning features or use of this software
14254225Speter *    must display the following acknowledgement:
15254225Speter *	This product includes software developed by the University of
16254225Speter *	California, Berkeley and its contributors.
17254225Speter * 4. Neither the name of the University nor the names of its contributors
18254225Speter *    may be used to endorse or promote products derived from this software
19254225Speter *    without specific prior written permission.
20254225Speter *
21254225Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22254225Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23254225Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24254225Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25254225Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26254225Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27254225Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28254225Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29254225Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30254225Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31254225Speter * SUCH DAMAGE.
32254225Speter */
33254225Speter
34254225Speter#if defined(LIBC_SCCS) && !defined(lint)
35254225Speterstatic char sccsid[] = "@(#)confstr.c	8.1 (Berkeley) 6/4/93";
36254225Speter#endif /* LIBC_SCCS and not lint */
37254225Speter#include <sys/cdefs.h>
38254225Speter__FBSDID("$FreeBSD: head/lib/libc/gen/confstr.c 114443 2003-05-01 19:03:14Z nectar $");
39254225Speter
40254225Speter#include <sys/param.h>
41254225Speter
42254225Speter#include <errno.h>
43254225Speter#include <limits.h>
44254225Speter#include <paths.h>
45254225Speter#include <string.h>
46254225Speter#include <unistd.h>
47254225Speter
48254225Speter
49254225Spetersize_t
50254225Speterconfstr(int name, char *buf, size_t len)
51254225Speter{
52254225Speter	const char *p;
53254225Speter	const char UPE[] = "unsupported programming environment";
54254225Speter
55254225Speter	switch (name) {
56254225Speter	case _CS_PATH:
57254225Speter		p = _PATH_STDPATH;
58254225Speter		goto docopy;
59254225Speter
60254225Speter		/*
61254225Speter		 * POSIX/SUS ``Programming Environments'' stuff
62254225Speter		 *
63254225Speter		 * We don't support more than one programming environment
64254225Speter		 * on any platform (yet), so we just return the empty
65254225Speter		 * string for the environment we are compiled for,
66254225Speter		 * and the string "unsupported programming environment"
67254225Speter		 * for anything else.  (The Standard says that if these
68254225Speter		 * values are used on a system which does not support
69254225Speter		 * this environment -- determined via sysconf() -- then
70254225Speter		 * the value we return is unspecified.  So, we return
71254225Speter		 * something which will cause obvious breakage.)
72254225Speter		 */
73254225Speter	case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
74254225Speter	case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
75254225Speter	case _CS_POSIX_V6_ILP32_OFF32_LIBS:
76254225Speter	case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
77254225Speter	case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
78254225Speter	case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
79254225Speter		/*
80254225Speter		 * These two environments are never supported.
81254225Speter		 */
82254225Speter		p = UPE;
83254225Speter		goto docopy;
84254225Speter
85254225Speter	case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
86254225Speter	case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
87254225Speter	case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
88254225Speter		if (sizeof(long) * CHAR_BIT == 32 &&
89254225Speter		    sizeof(off_t) > sizeof(long))
90254225Speter			p = "";
91254225Speter		else
92254225Speter			p = UPE;
93254225Speter		goto docopy;
94254225Speter
95254225Speter	case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
96254225Speter	case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
97254225Speter	case _CS_POSIX_V6_LP64_OFF64_LIBS:
98254225Speter		if (sizeof(long) * CHAR_BIT >= 64 &&
99254225Speter		    sizeof(void *) * CHAR_BIT >= 64 &&
100254225Speter		    sizeof(int) * CHAR_BIT >= 32 &&
101254225Speter		    sizeof(off_t) >= sizeof(long))
102254225Speter			p = "";
103254225Speter		else
104254225Speter			p = UPE;
105254225Speter		goto docopy;
106254225Speter
107254225Speter	case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:
108254225Speter		/* XXX - should have more complete coverage */
109254225Speter		if (sizeof(long) * CHAR_BIT >= 64)
110254225Speter			p = "_POSIX_V6_LP64_OFF64";
111254225Speter		else
112254225Speter			p = "_POSIX_V6_ILP32_OFFBIG";
113254225Speter		goto docopy;
114254225Speter
115254225Speterdocopy:
116254225Speter		if (len != 0 && buf != NULL)
117254225Speter			strlcpy(buf, p, len);
118254225Speter		return (strlen(p) + 1);
119254225Speter
120254225Speter	default:
121254225Speter		errno = EINVAL;
122254225Speter		return (0);
123254225Speter	}
124254225Speter	/* NOTREACHED */
125254225Speter}
126254225Speter