summaryrefslogtreecommitdiff
path: root/lib/libc/gen/confstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/gen/confstr.c')
-rw-r--r--lib/libc/gen/confstr.c112
1 files changed, 82 insertions, 30 deletions
diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c
index 57ddf720664..c4352648e51 100644
--- a/lib/libc/gen/confstr.c
+++ b/lib/libc/gen/confstr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: confstr.c,v 1.8 2006/12/04 15:02:25 otto Exp $ */
+/* $OpenBSD: confstr.c,v 1.9 2013/03/01 21:19:42 guenther Exp $ */
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
@@ -28,45 +28,97 @@
* SUCH DAMAGE.
*/
-#include <sys/param.h>
-#include <sys/sysctl.h>
-
#include <errno.h>
#include <paths.h>
-#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+
+static const char v6_width_restricted_envs[] = {
+#ifdef __LP64__
+ "POSIX_V6_LP64_OFF64\n"
+ "POSIX_V6_LPBIG_OFFBIG"
+#else
+ "POSIX_V6_ILP32_OFFBIG"
+#endif
+};
+
+static const char v7_width_restricted_envs[] = {
+#ifdef __LP64__
+ "POSIX_V7_LP64_OFF64\n"
+ "POSIX_V7_LPBIG_OFFBIG"
+#else
+ "POSIX_V7_ILP32_OFFBIG"
+#endif
+};
+
size_t
confstr(int name, char *buf, size_t len)
{
- size_t tlen;
- int mib[2], sverrno;
- char *p;
-
switch (name) {
case _CS_PATH:
- mib[0] = CTL_USER;
- mib[1] = USER_CS_PATH;
- if (sysctl(mib, 2, NULL, &tlen, NULL, 0) == -1)
- return (0);
- if (len != 0 && buf != NULL) {
- if ((p = malloc(tlen)) == NULL)
- return (0);
- if (sysctl(mib, 2, p, &tlen, NULL, 0) == -1) {
- sverrno = errno;
- free(p);
- errno = sverrno;
- return (0);
- }
- /*
- * POSIX 1003.2 requires partial return of
- * the string -- that should be *real* useful.
- */
- strlcpy(buf, p, len);
- free(p);
- }
- return (tlen + 1);
+ return (strlcpy(buf, _PATH_STDPATH, len));
+
+ /* no configuration-defined value */
+ case _CS_POSIX_V6_ILP32_OFF32_CFLAGS:
+ case _CS_POSIX_V6_ILP32_OFF32_LDFLAGS:
+ case _CS_POSIX_V6_ILP32_OFF32_LIBS:
+ case _CS_POSIX_V7_ILP32_OFF32_CFLAGS:
+ case _CS_POSIX_V7_ILP32_OFF32_LDFLAGS:
+ case _CS_POSIX_V7_ILP32_OFF32_LIBS:
+ return (0);
+
+ /* these are either NULL or empty, depending on the platform */
+ case _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS:
+ case _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS:
+ case _CS_POSIX_V6_ILP32_OFFBIG_LIBS:
+ case _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS:
+ case _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS:
+ case _CS_POSIX_V7_ILP32_OFFBIG_LIBS:
+#ifdef __LP64__
+ return (0);
+#else
+ if (len > 0)
+ buf[0] = '\0';
+ return (1);
+#endif
+ case _CS_POSIX_V6_LP64_OFF64_CFLAGS:
+ case _CS_POSIX_V6_LP64_OFF64_LDFLAGS:
+ case _CS_POSIX_V6_LP64_OFF64_LIBS:
+ case _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS:
+ case _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS:
+ case _CS_POSIX_V6_LPBIG_OFFBIG_LIBS:
+ case _CS_POSIX_V7_LP64_OFF64_CFLAGS:
+ case _CS_POSIX_V7_LP64_OFF64_LDFLAGS:
+ case _CS_POSIX_V7_LP64_OFF64_LIBS:
+ case _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS:
+ case _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS:
+ case _CS_POSIX_V7_LPBIG_OFFBIG_LIBS:
+#ifdef __LP64__
+ if (len > 0)
+ buf[0] = '\0';
+ return (1);
+#else
+ return (0);
+#endif
+
+ /* zero length strings */
+ case _CS_POSIX_V7_THREADS_CFLAGS:
+ case _CS_V6_ENV:
+ case _CS_V7_ENV:
+ if (len > 0)
+ buf[0] = '\0';
+ return (1);
+
+ case _CS_POSIX_V7_THREADS_LDFLAGS:
+ return (strlcpy(buf, "-lpthread", len));
+
+ case _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS:
+ return (strlcpy(buf, v6_width_restricted_envs, len));
+
+ case _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS:
+ return (strlcpy(buf, v7_width_restricted_envs, len));
+
default:
errno = EINVAL;
return (0);