confstr.c revision 100150
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 * 3. All advertising materials mentioning features or use of this software 141573Srgrimes * must display the following acknowledgement: 151573Srgrimes * This product includes software developed by the University of 161573Srgrimes * California, Berkeley and its contributors. 171573Srgrimes * 4. Neither the name of the University nor the names of its contributors 181573Srgrimes * may be used to endorse or promote products derived from this software 191573Srgrimes * without specific prior written permission. 201573Srgrimes * 211573Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221573Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231573Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241573Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251573Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261573Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271573Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281573Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291573Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301573Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311573Srgrimes * SUCH DAMAGE. 321573Srgrimes */ 331573Srgrimes 341573Srgrimes#if defined(LIBC_SCCS) && !defined(lint) 351573Srgrimesstatic char sccsid[] = "@(#)confstr.c 8.1 (Berkeley) 6/4/93"; 361573Srgrimes#endif /* LIBC_SCCS and not lint */ 3792986Sobrien#include <sys/cdefs.h> 3892986Sobrien__FBSDID("$FreeBSD: head/lib/libc/gen/confstr.c 100150 2002-07-15 22:43:03Z wollman $"); 391573Srgrimes 401573Srgrimes#include <sys/param.h> 411573Srgrimes 421573Srgrimes#include <errno.h> 43100149Swollman#include <limits.h> 441573Srgrimes#include <paths.h> 45100149Swollman#include <string.h> 461573Srgrimes#include <unistd.h> 471573Srgrimes 48100149Swollman 491573Srgrimessize_t 50100146Swollmanconfstr(int name, char *buf, size_t len) 511573Srgrimes{ 52100146Swollman const char *p; 53100149Swollman const char UPE[] = "unsupported programming environment"; 541573Srgrimes 551573Srgrimes switch (name) { 561573Srgrimes case _CS_PATH: 57100146Swollman p = _PATH_STDPATH; 58100146Swollman goto docopy; 59100146Swollman 60100149Swollman /* 61100149Swollman * POSIX/SUS ``Programming Environments'' stuff 62100149Swollman * 63100149Swollman * We don't support more than one programming environment 64100149Swollman * on any platform (yet), so we just return the empty 65100149Swollman * string for the environment we are compiled for, 66100149Swollman * and the string "unsupported programming environment" 67100149Swollman * for anything else. (The Standard says that if these 68100149Swollman * values are used on a system which does not support 69100149Swollman * this environment -- determined via sysconf() -- then 70100149Swollman * the value we return is unspecified. So, we return 71100149Swollman * something which will cause obvious breakage.) 72100149Swollman */ 73100149Swollman case _CS_POSIX_V6_ILP32_OFF32_CFLAGS: 74100149Swollman case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS: 75100149Swollman case _CS_POSIX_V6_ILP32_OFF32_LIBS: 76100150Swollman case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS: 77100150Swollman case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS: 78100150Swollman case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS: 79100149Swollman /* 80100150Swollman * These two environments are never supported. 81100149Swollman */ 82100149Swollman p = UPE; 83100149Swollman goto docopy; 84100149Swollman 85100149Swollman case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS: 86100149Swollman case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS: 87100149Swollman case _CS_POSIX_V6_ILP32_OFFBIG_LIBS: 88100149Swollman if (sizeof(long) * CHAR_BIT == 32 && 89100149Swollman sizeof(off_t) > sizeof(long)) 90100149Swollman p = ""; 91100149Swollman else 92100149Swollman p = UPE; 93100149Swollman goto docopy; 94100149Swollman 95100150Swollman case _CS_POSIX_V6_LP64_OFF64_CFLAGS: 96100150Swollman case _CS_POSIX_V6_LP64_OFF64_LDFLAGS: 97100150Swollman case _CS_POSIX_V6_LP64_OFF64_LIBS: 98100149Swollman if (sizeof(long) * CHAR_BIT >= 64 && 99100149Swollman sizeof(void *) * CHAR_BIT >= 64 && 100100149Swollman sizeof(int) * CHAR_BIT >= 32 && 101100149Swollman sizeof(off_t) >= sizeof(long)) 102100149Swollman p = ""; 103100149Swollman else 104100149Swollman p = UPE; 105100149Swollman goto docopy; 106100149Swollman 107100149Swollman case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS: 108100149Swollman if (sizeof(long) * CHAR_BIT >= 64) 109100150Swollman p = "_POSIX_V6_LPBIG_OFFBIG"; 110100149Swollman else 111100150Swollman p = "_POSIX_V6_ILP32_OFFBIG"; 112100149Swollman goto docopy; 113100149Swollman 114100146Swollmandocopy: 115100146Swollman if (len != 0 && buf != NULL) 116100146Swollman strlcpy(buf, p, len); 117100146Swollman return (strlen(p) + 1); 118100146Swollman 1191573Srgrimes default: 1201573Srgrimes errno = EINVAL; 1211573Srgrimes return (0); 1221573Srgrimes } 1231573Srgrimes /* NOTREACHED */ 1241573Srgrimes} 125