xref: /illumos-gate/usr/src/lib/libc/port/gen/confstr.c (revision 1da57d55)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
564e3e6f9Scraigm  * Common Development and Distribution License (the "License").
664e3e6f9Scraigm  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*7257d1b4Sraf 
227c478bd9Sstevel@tonic-gate /*
23*7257d1b4Sraf  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*7257d1b4Sraf #pragma	weak _confstr = confstr
2864e3e6f9Scraigm 
29*7257d1b4Sraf #include "lint.h"
307c478bd9Sstevel@tonic-gate #include "xpg6.h"
317c478bd9Sstevel@tonic-gate #include <sys/types.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <errno.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate typedef struct {
377c478bd9Sstevel@tonic-gate 	int	config_value;
387c478bd9Sstevel@tonic-gate 	char	*value;
397c478bd9Sstevel@tonic-gate } config;
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate /*
427c478bd9Sstevel@tonic-gate  * keep these in the same order as in sys/unistd.h
437c478bd9Sstevel@tonic-gate  */
447c478bd9Sstevel@tonic-gate static const config	default_conf[] = {
457c478bd9Sstevel@tonic-gate 	{ _CS_LFS_CFLAGS,	"-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
467c478bd9Sstevel@tonic-gate 	{ _CS_LFS_LDFLAGS,	""					},
477c478bd9Sstevel@tonic-gate 	{ _CS_LFS_LIBS,		""					},
487c478bd9Sstevel@tonic-gate 	{ _CS_LFS_LINTFLAGS,	"-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
497c478bd9Sstevel@tonic-gate 	{ _CS_LFS64_CFLAGS,	"-D_LARGEFILE64_SOURCE"			},
507c478bd9Sstevel@tonic-gate 	{ _CS_LFS64_LDFLAGS,	""					},
517c478bd9Sstevel@tonic-gate 	{ _CS_LFS64_LIBS,	""					},
527c478bd9Sstevel@tonic-gate 	{ _CS_LFS64_LINTFLAGS,	"-D_LARGEFILE64_SOURCE"			},
537c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFF32_CFLAGS,	""				},
547c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFF32_LDFLAGS,	""				},
557c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFF32_LIBS,	""				},
567c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFF32_LINTFLAGS, ""				},
577c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFFBIG_CFLAGS,
587c478bd9Sstevel@tonic-gate "-Xa -Usun -Usparc -Uunix -Ui386 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
597c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFFBIG_LDFLAGS, ""				},
607c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFFBIG_LIBS,	""				},
617c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_ILP32_OFFBIG_LINTFLAGS,
627c478bd9Sstevel@tonic-gate 		"-Xa -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"},
637c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_ILP32_OFF32_CFLAGS,	""			},
647c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_ILP32_OFF32_LDFLAGS,	""			},
657c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_ILP32_OFF32_LIBS,	""			},
667c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS,
677c478bd9Sstevel@tonic-gate "-Xa -Usun -Usparc -Uunix -Ui386 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" },
687c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS,	""			},
697c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_ILP32_OFFBIG_LIBS,	""			},
707c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS,
717c478bd9Sstevel@tonic-gate 		"POSIX_V6_ILP32_OFF32\nPOSIX_V6_ILP32_OFFBIG\n"
727c478bd9Sstevel@tonic-gate 		"POSIX_V6_LP64_OFF64\nPOSIX_V6_LPBIG_OFFBIG"		},
737c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LP64_OFF64_CFLAGS, "-xarch=generic64"		},
747c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LP64_OFF64_LDFLAGS,	"-xarch=generic64"		},
757c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LP64_OFF64_LIBS,	""				},
767c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LP64_OFF64_LINTFLAGS, "-xarch=generic64" 		},
777c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LPBIG_OFFBIG_CFLAGS, "-xarch=generic64" 		},
787c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "-xarch=generic64"		},
797c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LPBIG_OFFBIG_LIBS,	""				},
807c478bd9Sstevel@tonic-gate 	{ _CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "-xarch=generic64"		},
817c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_LP64_OFF64_CFLAGS, "-xarch=generic64"		},
827c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_LP64_OFF64_LDFLAGS, "-xarch=generic64"		},
837c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_LP64_OFF64_LIBS,	""				},
847c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS, "-xarch=generic64" 		},
857c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS, "-xarch=generic64"		},
867c478bd9Sstevel@tonic-gate 	{ _CS_POSIX_V6_LPBIG_OFFBIG_LIBS, ""				},
877c478bd9Sstevel@tonic-gate };
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	CS_ENTRY_COUNT (sizeof (default_conf) / sizeof (config))
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate size_t
confstr(int name,char * buf,size_t length)927c478bd9Sstevel@tonic-gate confstr(int name, char *buf, size_t length)
937c478bd9Sstevel@tonic-gate {
947c478bd9Sstevel@tonic-gate 	size_t			conf_length;
957c478bd9Sstevel@tonic-gate 	config			*entry;
967c478bd9Sstevel@tonic-gate 	int			i;
977c478bd9Sstevel@tonic-gate 	char			*path;
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate 	/* Keep _CS_PATH in sync with execvp.c */
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	if (name == _CS_PATH) {
1027c478bd9Sstevel@tonic-gate 		if (__xpg6 & _C99SUSv3_XPG6_sysconf_version)
103*7257d1b4Sraf 			path = "/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:"
104*7257d1b4Sraf 			    "/usr/bin:/opt/SUNWspro/bin";
1057c478bd9Sstevel@tonic-gate 		else
106*7257d1b4Sraf 			path = "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:"
107*7257d1b4Sraf 			    "/opt/SUNWspro/bin";
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 		conf_length = strlen(path) + 1;
1107c478bd9Sstevel@tonic-gate 		if (length != 0) {
1117c478bd9Sstevel@tonic-gate 			(void) strncpy(buf, path, length);
1127c478bd9Sstevel@tonic-gate 			buf[length - 1] = '\0';
1137c478bd9Sstevel@tonic-gate 		}
1147c478bd9Sstevel@tonic-gate 		return (conf_length);
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 	/*
1177c478bd9Sstevel@tonic-gate 	 * Make sure others are known configuration parameters
1187c478bd9Sstevel@tonic-gate 	 */
1197c478bd9Sstevel@tonic-gate 	entry = (config *)default_conf;
1207c478bd9Sstevel@tonic-gate 	for (i = 0; i < CS_ENTRY_COUNT; i++) {
1217c478bd9Sstevel@tonic-gate 		if (name == entry->config_value) {
1227c478bd9Sstevel@tonic-gate 			/*
1237c478bd9Sstevel@tonic-gate 			 * Copy out the parameter from our tables.
1247c478bd9Sstevel@tonic-gate 			 */
1257c478bd9Sstevel@tonic-gate 			conf_length = strlen(entry->value) + 1;
1267c478bd9Sstevel@tonic-gate 			if (length != 0) {
1277c478bd9Sstevel@tonic-gate 				(void) strncpy(buf, entry->value, length);
1287c478bd9Sstevel@tonic-gate 				buf[length - 1] = '\0';
1297c478bd9Sstevel@tonic-gate 			}
1307c478bd9Sstevel@tonic-gate 			return (conf_length);
1317c478bd9Sstevel@tonic-gate 		}
1327c478bd9Sstevel@tonic-gate 		entry++;
1337c478bd9Sstevel@tonic-gate 	}
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	/* If the entry was not found in table return an error */
1367c478bd9Sstevel@tonic-gate 	errno = EINVAL;
1377c478bd9Sstevel@tonic-gate 	return ((size_t)0);
1387c478bd9Sstevel@tonic-gate }
139