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