import less(1)
[unleashed/tickless.git] / usr / src / lib / libc / port / gen / confstr.c
bloba778097c5d03f059e5ded71be3fb45c1cbfb8003
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #pragma weak _confstr = confstr
31 #include "lint.h"
32 #include "xpg6.h"
33 #include <sys/types.h>
34 #include <unistd.h>
35 #include <errno.h>
36 #include <string.h>
38 typedef struct {
39 int config_value;
40 char *value;
41 } config;
44 * keep these in the same order as in sys/unistd.h
46 static const config default_conf[] = {
47 { _CS_LFS_CFLAGS, "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
48 { _CS_LFS_LDFLAGS, "" },
49 { _CS_LFS_LIBS, "" },
50 { _CS_LFS_LINTFLAGS, "-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
51 { _CS_LFS64_CFLAGS, "-D_LARGEFILE64_SOURCE" },
52 { _CS_LFS64_LDFLAGS, "" },
53 { _CS_LFS64_LIBS, "" },
54 { _CS_LFS64_LINTFLAGS, "-D_LARGEFILE64_SOURCE" },
55 { _CS_XBS5_ILP32_OFF32_CFLAGS, "" },
56 { _CS_XBS5_ILP32_OFF32_LDFLAGS, "" },
57 { _CS_XBS5_ILP32_OFF32_LIBS, "" },
58 { _CS_XBS5_ILP32_OFF32_LINTFLAGS, "" },
59 { _CS_XBS5_ILP32_OFFBIG_CFLAGS,
60 "-Xa -Usun -Usparc -Uunix -Ui386 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
61 { _CS_XBS5_ILP32_OFFBIG_LDFLAGS, "" },
62 { _CS_XBS5_ILP32_OFFBIG_LIBS, "" },
63 { _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
64 "-Xa -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"},
65 { _CS_POSIX_V6_ILP32_OFF32_CFLAGS, "" },
66 { _CS_POSIX_V6_ILP32_OFF32_LDFLAGS, "" },
67 { _CS_POSIX_V6_ILP32_OFF32_LIBS, "" },
68 { _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
69 "-Xa -Usun -Usparc -Uunix -Ui386 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
70 { _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS, "" },
71 { _CS_POSIX_V6_ILP32_OFFBIG_LIBS, "" },
72 { _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS,
73 "POSIX_V6_ILP32_OFF32\nPOSIX_V6_ILP32_OFFBIG\n"
74 "POSIX_V6_LP64_OFF64\nPOSIX_V6_LPBIG_OFFBIG" },
75 { _CS_XBS5_LP64_OFF64_CFLAGS, "-xarch=generic64" },
76 { _CS_XBS5_LP64_OFF64_LDFLAGS, "-xarch=generic64" },
77 { _CS_XBS5_LP64_OFF64_LIBS, "" },
78 { _CS_XBS5_LP64_OFF64_LINTFLAGS, "-xarch=generic64" },
79 { _CS_XBS5_LPBIG_OFFBIG_CFLAGS, "-xarch=generic64" },
80 { _CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "-xarch=generic64" },
81 { _CS_XBS5_LPBIG_OFFBIG_LIBS, "" },
82 { _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "-xarch=generic64" },
83 { _CS_POSIX_V6_LP64_OFF64_CFLAGS, "-xarch=generic64" },
84 { _CS_POSIX_V6_LP64_OFF64_LDFLAGS, "-xarch=generic64" },
85 { _CS_POSIX_V6_LP64_OFF64_LIBS, "" },
86 { _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, "-xarch=generic64" },
87 { _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, "-xarch=generic64" },
88 { _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, "" },
91 #define CS_ENTRY_COUNT (sizeof (default_conf) / sizeof (config))
93 size_t
94 confstr(int name, char *buf, size_t length)
96 size_t conf_length;
97 config *entry;
98 int i;
99 char *path;
101 /* Keep _CS_PATH in sync with execvp.c */
103 if (name == _CS_PATH) {
104 path = "/usr/bin:/usr/ccs/bin:"
105 "/opt/SUNWspro/bin";
107 conf_length = strlen(path) + 1;
108 if (length != 0) {
109 (void) strncpy(buf, path, length);
110 buf[length - 1] = '\0';
112 return (conf_length);
115 * Make sure others are known configuration parameters
117 entry = (config *)default_conf;
118 for (i = 0; i < CS_ENTRY_COUNT; i++) {
119 if (name == entry->config_value) {
121 * Copy out the parameter from our tables.
123 conf_length = strlen(entry->value) + 1;
124 if (length != 0) {
125 (void) strncpy(buf, entry->value, length);
126 buf[length - 1] = '\0';
128 return (conf_length);
130 entry++;
133 /* If the entry was not found in table return an error */
134 errno = EINVAL;
135 return ((size_t)0);