From 603a6e79d816d21d57d45f7cb0cc1a2022183d5b Mon Sep 17 00:00:00 2001 From: Garrett Wollman Date: Mon, 15 Jul 2002 22:21:33 +0000 Subject: [PATCH] Support POSIX/SUS ``programming environment'' mistake in confstr(). --- include/unistd.h | 15 ++++++++++ lib/libc/gen/confstr.c | 63 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-) diff --git a/include/unistd.h b/include/unistd.h index 7abf307a9c48..099cf53268d5 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -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 /* diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c index ad2e5a0959c3..592a3eff2ecf 100644 --- a/lib/libc/gen/confstr.c +++ b/lib/libc/gen/confstr.c @@ -40,20 +40,81 @@ __FBSDID("$FreeBSD$"); #include #include +#include #include -#include #include +#include + 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);