11573Srgrimes/*-
21573Srgrimes * Copyright (c) 1993
31573Srgrimes *	The Regents of the University of California.  All rights reserved.
41573Srgrimes *
51573Srgrimes * Redistribution and use in source and binary forms, with or without
61573Srgrimes * modification, are permitted provided that the following conditions
71573Srgrimes * are met:
81573Srgrimes * 1. Redistributions of source code must retain the above copyright
91573Srgrimes *    notice, this list of conditions and the following disclaimer.
101573Srgrimes * 2. Redistributions in binary form must reproduce the above copyright
111573Srgrimes *    notice, this list of conditions and the following disclaimer in the
121573Srgrimes *    documentation and/or other materials provided with the distribution.
131573Srgrimes * 4. Neither the name of the University nor the names of its contributors
141573Srgrimes *    may be used to endorse or promote products derived from this software
151573Srgrimes *    without specific prior written permission.
161573Srgrimes *
171573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
181573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
191573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
201573Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
211573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
221573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
241573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
251573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
261573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
271573Srgrimes * SUCH DAMAGE.
281573Srgrimes */
291573Srgrimes
301573Srgrimes#if defined(LIBC_SCCS) && !defined(lint)
311573Srgrimesstatic char sccsid[] = "@(#)confstr.c	8.1 (Berkeley) 6/4/93";
321573Srgrimes#endif /* LIBC_SCCS and not lint */
3392986Sobrien#include <sys/cdefs.h>
3492986Sobrien__FBSDID("$FreeBSD$");
351573Srgrimes
361573Srgrimes#include <sys/param.h>
37114443Snectar
381573Srgrimes#include <errno.h>
39100149Swollman#include <limits.h>
401573Srgrimes#include <paths.h>
41100149Swollman#include <string.h>
421573Srgrimes#include <unistd.h>
431573Srgrimes
44100149Swollman
451573Srgrimessize_t
46100146Swollmanconfstr(int name, char *buf, size_t len)
471573Srgrimes{
48100146Swollman	const char *p;
49100149Swollman	const char UPE[] = "unsupported programming environment";
501573Srgrimes
511573Srgrimes	switch (name) {
521573Srgrimes	case _CS_PATH:
53100146Swollman		p = _PATH_STDPATH;
54100146Swollman		goto docopy;
55100146Swollman
56100149Swollman		/*
57100149Swollman		 * POSIX/SUS ``Programming Environments'' stuff
58100149Swollman		 *
59100149Swollman		 * We don't support more than one programming environment
60100149Swollman		 * on any platform (yet), so we just return the empty
61100149Swollman		 * string for the environment we are compiled for,
62100149Swollman		 * and the string "unsupported programming environment"
63100149Swollman		 * for anything else.  (The Standard says that if these
64100149Swollman		 * values are used on a system which does not support
65100149Swollman		 * this environment -- determined via sysconf() -- then
66100149Swollman		 * the value we return is unspecified.  So, we return
67100149Swollman		 * something which will cause obvious breakage.)
68100149Swollman		 */
69100149Swollman	case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
70100149Swollman	case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
71100149Swollman	case _CS_POSIX_V6_ILP32_OFF32_LIBS:
72100150Swollman	case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
73100150Swollman	case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
74100150Swollman	case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
75100149Swollman		/*
76100150Swollman		 * These two environments are never supported.
77100149Swollman		 */
78100149Swollman		p = UPE;
79100149Swollman		goto docopy;
80100149Swollman
81100149Swollman	case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
82100149Swollman	case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
83100149Swollman	case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
84100149Swollman		if (sizeof(long) * CHAR_BIT == 32 &&
85100149Swollman		    sizeof(off_t) > sizeof(long))
86100149Swollman			p = "";
87100149Swollman		else
88100149Swollman			p = UPE;
89100149Swollman		goto docopy;
90100149Swollman
91100150Swollman	case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
92100150Swollman	case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
93100150Swollman	case _CS_POSIX_V6_LP64_OFF64_LIBS:
94100149Swollman		if (sizeof(long) * CHAR_BIT >= 64 &&
95100149Swollman		    sizeof(void *) * CHAR_BIT >= 64 &&
96100149Swollman		    sizeof(int) * CHAR_BIT >= 32 &&
97100149Swollman		    sizeof(off_t) >= sizeof(long))
98100149Swollman			p = "";
99100149Swollman		else
100100149Swollman			p = UPE;
101100149Swollman		goto docopy;
102100149Swollman
103100149Swollman	case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:
104103593Swollman		/* XXX - should have more complete coverage */
105100149Swollman		if (sizeof(long) * CHAR_BIT >= 64)
106103593Swollman			p = "_POSIX_V6_LP64_OFF64";
107100149Swollman		else
108100150Swollman			p = "_POSIX_V6_ILP32_OFFBIG";
109100149Swollman		goto docopy;
110100149Swollman
111100146Swollmandocopy:
112100146Swollman		if (len != 0 && buf != NULL)
113114443Snectar			strlcpy(buf, p, len);
114100146Swollman		return (strlen(p) + 1);
115100146Swollman
1161573Srgrimes	default:
1171573Srgrimes		errno = EINVAL;
1181573Srgrimes		return (0);
1191573Srgrimes	}
1201573Srgrimes	/* NOTREACHED */
1211573Srgrimes}
122