summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPhilip Guenther <guenther@cvs.openbsd.org>2013-03-01 21:19:43 +0000
committerPhilip Guenther <guenther@cvs.openbsd.org>2013-03-01 21:19:43 +0000
commit1d12523ffeb589ebb431f5cced7dff9df89cc904 (patch)
treea3449ef66e2e7b715ea9f0612690a1423deaee23 /lib
parent7fa029faeebb729acc7e0ff0a486ff0161984c3a (diff)
Adds the (somewhat silly) _CS_V[67]_ENV and _CS_POSIX_V[67]_* defines
to <unistd.h> and confstr(3) per POSIX 1003.1-2008 Change confstr(_CS_PATH) to operate directly instead of calling sysctl(3) ports build tested by espie@
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/confstr.3116
-rw-r--r--lib/libc/gen/confstr.c112
2 files changed, 180 insertions, 48 deletions
diff --git a/lib/libc/gen/confstr.3 b/lib/libc/gen/confstr.3
index 46f6a5b1af6..8b4a5b3cecb 100644
--- a/lib/libc/gen/confstr.3
+++ b/lib/libc/gen/confstr.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: confstr.3,v 1.16 2007/05/31 19:19:28 jmc Exp $
+.\" $OpenBSD: confstr.3,v 1.17 2013/03/01 21:19:42 guenther Exp $
.\"
.\" Copyright (c) 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: May 31 2007 $
+.Dd $Mdocdate: March 1 2013 $
.Dt CONFSTR 3
.Os
.Sh NAME
@@ -38,11 +38,6 @@
.Ft size_t
.Fn confstr "int name" "char *buf" "size_t len"
.Sh DESCRIPTION
-.Bf -symbolic
-This interface is obsoleted by
-.Xr sysctl 3 .
-.Ef
-.Pp
The
.Fn confstr
function provides a method for applications to get configuration
@@ -71,11 +66,102 @@ has a value; up to
The copied value is always NUL terminated.
.Pp
The available values are as follows:
-.Bl -tag -width "123456"
+.Bl -tag -width "123456" -compact
.It Li _CS_PATH
Return a value for the
.Ev PATH
environment variable that finds all the standard utilities.
+.Pp
+.It Li _CS_V7_ENV
+Return a space separated list of environment variable assignments
+(other than
+.Ev PATH )
+necessary for obtaining a shell environment compliant with
+.St -p1003.1-2008 .
+.Pp
+.It Li _CS_V6_ENV
+Return a space separated list of environment variable assignments
+(other than
+.Ev PATH )
+necessary for obtaining a shell environment compliant with
+.St -p1003.1-2001 .
+.Pp
+.It Li _CS_POSIX_V7_THREADS_CFLAGS
+Return the compiler flags for compiling objects in a program that
+uses multiple threads.
+.Pp
+.It Li _CS_POSIX_V7_THREADS_LDFLAGS
+Return the linker flags for linking an executable that uses multiple
+threads.
+.Pp
+.It Li _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS
+.It Li _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS
+Return a newline separated list of supported compilation environments
+in which none of the following types are wider than type
+.Vt long :
+.Vt blksize_t , cc_t , mode_t , nfds_t , pid_t , ptrdiff_t , size_t ,
+.Vt speed_t , ssize_t , suseconds_t , tcflag_t , wchar_t ,
+and
+.Vt wint_t .
+.Pp
+.It Li _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS
+.It Li _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS
+.It Li _CS_POSIX_V7_ILP32_OFFBIG_LIBS
+.It Li _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS
+.It Li _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS
+.It Li _CS_POSIX_V6_ILP32_OFFBIG_LIBS
+If
+.Fn sysconf _SC_V7_ILP32_OFFBIG
+returns a value greater than zero,
+return the compiler flags for compiling objects,
+the linker flags for linking an executable,
+or the linker arguments for additional libraries, respectively,
+for a compilation environment with 32-bit
+.Vt int , long ,
+and
+.Vt pointer
+types and an
+.Vt off_t
+type that has a width of at least 64 bits.
+Otherwise, the result is unspecified.
+.Pp
+.It Li _CS_POSIX_V7_LP64_OFF64_CFLAGS
+.It Li _CS_POSIX_V7_LP64_OFF64_LDFLAGS
+.It Li _CS_POSIX_V7_LP64_OFF64_LIBS
+.It Li _CS_POSIX_V6_LP64_OFF64_CFLAGS
+.It Li _CS_POSIX_V6_LP64_OFF64_LDFLAGS
+.It Li _CS_POSIX_V6_LP64_OFF64_LIBS
+If
+.Fn sysconf _SC_V7_LP64_OFF64
+returns a value greater than zero,
+return the compiler flags for compiling objects,
+the linker flags for linking an executable,
+or the linker arguments for additional libraries, respectively,
+for a compilation environment with 64-bit
+.Vt int , long , pointer ,
+and
+.Vt off_t
+types.
+Otherwise, the result is unspecified.
+.Pp
+.It Li _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS
+.It Li _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS
+.It Li _CS_POSIX_V7_LPBIG_OFFBIG_LIBS
+.It Li _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS
+.It Li _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS
+.It Li _CS_POSIX_V6_LPBIG_OFFBIG_LIBS
+If
+.Fn sysconf _SC_V7_LPBIG_OFFBIG
+returns a value greater than zero,
+return the compiler flags for compiling objects,
+the linker flags for linking an executable,
+or the linker arguments for additional libraries, respectively,
+for a compilation environment with
+.Vt int , long , pointer ,
+and
+.Vt off_t
+types that all have widths of at least 64 bits.
+Otherwise, the result is unspecified.
.El
.Sh RETURN VALUES
If the call to
@@ -97,14 +183,7 @@ was truncated.
.Sh ERRORS
The
.Nm
-function may fail and set
-.Va errno
-for any of the errors specified for the library functions
-.Xr malloc 3
-and
-.Xr sysctl 3 .
-.Pp
-In addition, the following errors may be reported:
+function will fail if:
.Bl -tag -width Er
.It Bq Er EINVAL
The value of the
@@ -112,12 +191,13 @@ The value of the
argument is invalid.
.El
.Sh SEE ALSO
-.Xr sysctl 3
+.Xr pathconf 2 ,
+.Xr sysconf 3
.Sh STANDARDS
The
.Nm
function conforms to
-.St -p1003.2-92 .
+.St -p1003.1-2008 .
.Sh HISTORY
The
.Nm
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);