confstr.c revision 259065
154359Sroberto/*- 254359Sroberto * Copyright (c) 1993 354359Sroberto * The Regents of the University of California. All rights reserved. 454359Sroberto * 554359Sroberto * Redistribution and use in source and binary forms, with or without 654359Sroberto * modification, are permitted provided that the following conditions 754359Sroberto * are met: 854359Sroberto * 1. Redistributions of source code must retain the above copyright 954359Sroberto * notice, this list of conditions and the following disclaimer. 1054359Sroberto * 2. Redistributions in binary form must reproduce the above copyright 1154359Sroberto * notice, this list of conditions and the following disclaimer in the 1254359Sroberto * documentation and/or other materials provided with the distribution. 1354359Sroberto * 4. Neither the name of the University nor the names of its contributors 1454359Sroberto * may be used to endorse or promote products derived from this software 1554359Sroberto * without specific prior written permission. 1654359Sroberto * 1754359Sroberto * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1854359Sroberto * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1954359Sroberto * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2054359Sroberto * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2154359Sroberto * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2282498Sroberto * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2382498Sroberto * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2482498Sroberto * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2554359Sroberto * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2654359Sroberto * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2754359Sroberto * SUCH DAMAGE. 2854359Sroberto */ 2954359Sroberto 3054359Sroberto#if defined(LIBC_SCCS) && !defined(lint) 3154359Srobertostatic char sccsid[] = "@(#)confstr.c 8.1 (Berkeley) 6/4/93"; 3254359Sroberto#endif /* LIBC_SCCS and not lint */ 3354359Sroberto#include <sys/cdefs.h> 3454359Sroberto__FBSDID("$FreeBSD: releng/10.0/lib/libc/gen/confstr.c 165903 2007-01-09 00:28:16Z imp $"); 3554359Sroberto 3654359Sroberto#include <sys/param.h> 3754359Sroberto 3854359Sroberto#include <errno.h> 3954359Sroberto#include <limits.h> 4054359Sroberto#include <paths.h> 4154359Sroberto#include <string.h> 4254359Sroberto#include <unistd.h> 4354359Sroberto 4454359Sroberto 4554359Srobertosize_t 4654359Srobertoconfstr(int name, char *buf, size_t len) 4754359Sroberto{ 4854359Sroberto const char *p; 4954359Sroberto const char UPE[] = "unsupported programming environment"; 5054359Sroberto 5154359Sroberto switch (name) { 5254359Sroberto case _CS_PATH: 5354359Sroberto p = _PATH_STDPATH; 5454359Sroberto goto docopy; 5554359Sroberto 5654359Sroberto /* 5754359Sroberto * POSIX/SUS ``Programming Environments'' stuff 5854359Sroberto * 5954359Sroberto * We don't support more than one programming environment 6054359Sroberto * on any platform (yet), so we just return the empty 6154359Sroberto * string for the environment we are compiled for, 6254359Sroberto * and the string "unsupported programming environment" 6354359Sroberto * for anything else. (The Standard says that if these 6454359Sroberto * values are used on a system which does not support 6554359Sroberto * this environment -- determined via sysconf() -- then 6654359Sroberto * the value we return is unspecified. So, we return 6754359Sroberto * something which will cause obvious breakage.) 6854359Sroberto */ 6954359Sroberto case _CS_POSIX_V6_ILP32_OFF32_CFLAGS: 70285612Sdelphij case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS: 71285612Sdelphij case _CS_POSIX_V6_ILP32_OFF32_LIBS: 72285612Sdelphij case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS: 73285612Sdelphij case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS: 7454359Sroberto case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS: 7554359Sroberto /* 7654359Sroberto * These two environments are never supported. 7754359Sroberto */ 7854359Sroberto p = UPE; 7954359Sroberto goto docopy; 8054359Sroberto 8154359Sroberto case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS: 8254359Sroberto case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS: 8354359Sroberto case _CS_POSIX_V6_ILP32_OFFBIG_LIBS: 8454359Sroberto if (sizeof(long) * CHAR_BIT == 32 && 8554359Sroberto sizeof(off_t) > sizeof(long)) 8654359Sroberto p = ""; 8754359Sroberto else 8854359Sroberto p = UPE; 8954359Sroberto goto docopy; 9054359Sroberto 9154359Sroberto case _CS_POSIX_V6_LP64_OFF64_CFLAGS: 9254359Sroberto case _CS_POSIX_V6_LP64_OFF64_LDFLAGS: 9354359Sroberto case _CS_POSIX_V6_LP64_OFF64_LIBS: 9454359Sroberto if (sizeof(long) * CHAR_BIT >= 64 && 9554359Sroberto sizeof(void *) * CHAR_BIT >= 64 && 9654359Sroberto sizeof(int) * CHAR_BIT >= 32 && 9754359Sroberto sizeof(off_t) >= sizeof(long)) 9854359Sroberto p = ""; 9954359Sroberto else 10054359Sroberto p = UPE; 10154359Sroberto goto docopy; 10254359Sroberto 10354359Sroberto case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS: 10454359Sroberto /* XXX - should have more complete coverage */ 10554359Sroberto if (sizeof(long) * CHAR_BIT >= 64) 10654359Sroberto p = "_POSIX_V6_LP64_OFF64"; 107285612Sdelphij else 10854359Sroberto p = "_POSIX_V6_ILP32_OFFBIG"; 10954359Sroberto goto docopy; 11054359Sroberto 11154359Srobertodocopy: 112285612Sdelphij if (len != 0 && buf != NULL) 113285612Sdelphij strlcpy(buf, p, len); 11454359Sroberto return (strlen(p) + 1); 11554359Sroberto 11654359Sroberto default: 11754359Sroberto errno = EINVAL; 11854359Sroberto return (0); 119285612Sdelphij } 12054359Sroberto /* NOTREACHED */ 121285612Sdelphij} 12254359Sroberto