/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 19934* The Regents of the University of California. All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14* 3. Neither the name of the University nor the names of its contributors15* may be used to endorse or promote products derived from this software16* without specific prior written permission.17*18* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND19* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE20* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE21* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE22* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL23* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS24* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)25* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT26* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY27* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF28* SUCH DAMAGE.29*/3031#include <sys/param.h>3233#include <errno.h>34#include <limits.h>35#include <paths.h>36#include <string.h>37#include <unistd.h>383940size_t41confstr(int name, char *buf, size_t len)42{43const char *p;44const char UPE[] = "unsupported programming environment";4546switch (name) {47case _CS_PATH:48p = _PATH_STDPATH;49goto docopy;5051/*52* POSIX/SUS ``Programming Environments'' stuff53*54* We don't support more than one programming environment55* on any platform (yet), so we just return the empty56* string for the environment we are compiled for,57* and the string "unsupported programming environment"58* for anything else. (The Standard says that if these59* values are used on a system which does not support60* this environment -- determined via sysconf() -- then61* the value we return is unspecified. So, we return62* something which will cause obvious breakage.)63*/64case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:65case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:66case _CS_POSIX_V6_ILP32_OFF32_LIBS:67case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:68case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:69case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:70/*71* These two environments are never supported.72*/73p = UPE;74goto docopy;7576case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:77case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:78case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:79if (sizeof(long) * CHAR_BIT == 32 &&80sizeof(off_t) > sizeof(long))81p = "";82else83p = UPE;84goto docopy;8586case _CS_POSIX_V6_LP64_OFF64_CFLAGS:87case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:88case _CS_POSIX_V6_LP64_OFF64_LIBS:89if (sizeof(long) * CHAR_BIT >= 64 &&90sizeof(void *) * CHAR_BIT >= 64 &&91sizeof(int) * CHAR_BIT >= 32 &&92sizeof(off_t) >= sizeof(long))93p = "";94else95p = UPE;96goto docopy;9798case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:99/* XXX - should have more complete coverage */100if (sizeof(long) * CHAR_BIT >= 64)101p = "_POSIX_V6_LP64_OFF64";102else103p = "_POSIX_V6_ILP32_OFFBIG";104goto docopy;105106docopy:107if (len != 0 && buf != NULL)108strlcpy(buf, p, len);109return (strlen(p) + 1);110111default:112errno = EINVAL;113return (0);114}115/* NOTREACHED */116}117118119