xref: /illumos-gate/usr/src/lib/libc/port/gen/confstr.c (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma	weak _confstr = confstr
28 
29 #include "lint.h"
30 #include "xpg6.h"
31 #include <sys/types.h>
32 #include <unistd.h>
33 #include <errno.h>
34 #include <string.h>
35 
36 typedef struct {
37 	int	config_value;
38 	char	*value;
39 } config;
40 
41 /*
42  * keep these in the same order as in sys/unistd.h
43  */
44 static const config	default_conf[] = {
45 	{ _CS_LFS_CFLAGS,	"-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
46 	{ _CS_LFS_LDFLAGS,	""					},
47 	{ _CS_LFS_LIBS,		""					},
48 	{ _CS_LFS_LINTFLAGS,	"-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
49 	{ _CS_LFS64_CFLAGS,	"-D_LARGEFILE64_SOURCE"			},
50 	{ _CS_LFS64_LDFLAGS,	""					},
51 	{ _CS_LFS64_LIBS,	""					},
52 	{ _CS_LFS64_LINTFLAGS,	"-D_LARGEFILE64_SOURCE"			},
53 	{ _CS_XBS5_ILP32_OFF32_CFLAGS,	""				},
54 	{ _CS_XBS5_ILP32_OFF32_LDFLAGS,	""				},
55 	{ _CS_XBS5_ILP32_OFF32_LIBS,	""				},
56 	{ _CS_XBS5_ILP32_OFF32_LINTFLAGS, ""				},
57 	{ _CS_XBS5_ILP32_OFFBIG_CFLAGS,
58 "-Xa -Usun -Usparc -Uunix -Ui386 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
59 	{ _CS_XBS5_ILP32_OFFBIG_LDFLAGS, ""				},
60 	{ _CS_XBS5_ILP32_OFFBIG_LIBS,	""				},
61 	{ _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
62 		"-Xa -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"},
63 	{ _CS_POSIX_V6_ILP32_OFF32_CFLAGS,	""			},
64 	{ _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,	""			},
65 	{ _CS_POSIX_V6_ILP32_OFF32_LIBS,	""			},
66 	{ _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
67 "-Xa -Usun -Usparc -Uunix -Ui386 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
68 	{ _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,	""			},
69 	{ _CS_POSIX_V6_ILP32_OFFBIG_LIBS,	""			},
70 	{ _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS,
71 		"POSIX_V6_ILP32_OFF32\nPOSIX_V6_ILP32_OFFBIG\n"
72 		"POSIX_V6_LP64_OFF64\nPOSIX_V6_LPBIG_OFFBIG"		},
73 	{ _CS_XBS5_LP64_OFF64_CFLAGS, "-xarch=generic64"		},
74 	{ _CS_XBS5_LP64_OFF64_LDFLAGS,	"-xarch=generic64"		},
75 	{ _CS_XBS5_LP64_OFF64_LIBS,	""				},
76 	{ _CS_XBS5_LP64_OFF64_LINTFLAGS, "-xarch=generic64" 		},
77 	{ _CS_XBS5_LPBIG_OFFBIG_CFLAGS, "-xarch=generic64" 		},
78 	{ _CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "-xarch=generic64"		},
79 	{ _CS_XBS5_LPBIG_OFFBIG_LIBS,	""				},
80 	{ _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "-xarch=generic64"		},
81 	{ _CS_POSIX_V6_LP64_OFF64_CFLAGS, "-xarch=generic64"		},
82 	{ _CS_POSIX_V6_LP64_OFF64_LDFLAGS, "-xarch=generic64"		},
83 	{ _CS_POSIX_V6_LP64_OFF64_LIBS,	""				},
84 	{ _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, "-xarch=generic64" 		},
85 	{ _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, "-xarch=generic64"		},
86 	{ _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, ""				},
87 };
88 
89 #define	CS_ENTRY_COUNT (sizeof (default_conf) / sizeof (config))
90 
91 size_t
92 confstr(int name, char *buf, size_t length)
93 {
94 	size_t			conf_length;
95 	config			*entry;
96 	int			i;
97 	char			*path;
98 
99 	/* Keep _CS_PATH in sync with execvp.c */
100 
101 	if (name == _CS_PATH) {
102 		if (__xpg6 & _C99SUSv3_XPG6_sysconf_version)
103 			path = "/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:"
104 			    "/usr/bin:/opt/SUNWspro/bin";
105 		else
106 			path = "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:"
107 			    "/opt/SUNWspro/bin";
108 
109 		conf_length = strlen(path) + 1;
110 		if (length != 0) {
111 			(void) strncpy(buf, path, length);
112 			buf[length - 1] = '\0';
113 		}
114 		return (conf_length);
115 	}
116 	/*
117 	 * Make sure others are known configuration parameters
118 	 */
119 	entry = (config *)default_conf;
120 	for (i = 0; i < CS_ENTRY_COUNT; i++) {
121 		if (name == entry->config_value) {
122 			/*
123 			 * Copy out the parameter from our tables.
124 			 */
125 			conf_length = strlen(entry->value) + 1;
126 			if (length != 0) {
127 				(void) strncpy(buf, entry->value, length);
128 				buf[length - 1] = '\0';
129 			}
130 			return (conf_length);
131 		}
132 		entry++;
133 	}
134 
135 	/* If the entry was not found in table return an error */
136 	errno = EINVAL;
137 	return ((size_t)0);
138 }
139