Support POSIX/SUS ``programming environment'' mistake in confstr().

This commit is contained in:
wollman 2002-07-15 22:21:33 +00:00
parent e52f5b3dbc
commit f62ac07676
2 changed files with 77 additions and 1 deletions

View File

@ -167,6 +167,21 @@ int fchown(int, uid_t, gid_t);
int gethostname(char *, int /* socklen_t */);
int setegid(gid_t);
int seteuid(uid_t);
/* X/Open mistake copied by POSIX */
#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 2
#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 3
#define _CS_POSIX_V6_ILP32_OFF32_LIBS 4
#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 5
#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 6
#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 7
#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 8
#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 9
#define _CS_POSIX_V6_LP64_OFF64_LIBS 10
#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 11
#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 12
#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 13
#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 14
#endif
/*

View File

@ -40,20 +40,81 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <errno.h>
#include <limits.h>
#include <paths.h>
#include <unistd.h>
#include <string.h>
#include <unistd.h>
size_t
confstr(int name, char *buf, size_t len)
{
const char *p;
const char UPE[] = "unsupported programming environment";
switch (name) {
case _CS_PATH:
p = _PATH_STDPATH;
goto docopy;
/*
* POSIX/SUS ``Programming Environments'' stuff
*
* We don't support more than one programming environment
* on any platform (yet), so we just return the empty
* string for the environment we are compiled for,
* and the string "unsupported programming environment"
* for anything else. (The Standard says that if these
* values are used on a system which does not support
* this environment -- determined via sysconf() -- then
* the value we return is unspecified. So, we return
* something which will cause obvious breakage.)
*
* Note that the _V6_LP64_OFF64 is actually an *I*LP64
* environment; FreeBSD's LP64 architectures use the
* _V6_LPBIG_OFFBIG environment instead.
*/
case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
case _CS_POSIX_V6_ILP32_OFF32_LIBS:
case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
case _CS_POSIX_V6_LP64_OFF64_LIBS:
/*
* These six environments are never supported.
*/
p = UPE;
goto docopy;
case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
if (sizeof(long) * CHAR_BIT == 32 &&
sizeof(off_t) > sizeof(long))
p = "";
else
p = UPE;
goto docopy;
case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
if (sizeof(long) * CHAR_BIT >= 64 &&
sizeof(void *) * CHAR_BIT >= 64 &&
sizeof(int) * CHAR_BIT >= 32 &&
sizeof(off_t) >= sizeof(long))
p = "";
else
p = UPE;
goto docopy;
case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:
if (sizeof(long) * CHAR_BIT >= 64)
p = "_V6_LPBIG_OFFBIG";
else
p = "_V6_ILP32_OFFBIG";
goto docopy;
docopy:
if (len != 0 && buf != NULL)
strlcpy(buf, p, len);