Home | History | Annotate | Download | only in gen
      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 ident	"%Z%%M%	%I%	%E% SMI"
     28 
     29 #pragma	weak _confstr = confstr
     30 
     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>
     37 
     38 typedef struct {
     39 	int	config_value;
     40 	char	*value;
     41 } config;
     42 
     43 /*
     44  * keep these in the same order as in sys/unistd.h
     45  */
     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, ""				},
     89 };
     90 
     91 #define	CS_ENTRY_COUNT (sizeof (default_conf) / sizeof (config))
     92 
     93 size_t
     94 confstr(int name, char *buf, size_t length)
     95 {
     96 	size_t			conf_length;
     97 	config			*entry;
     98 	int			i;
     99 	char			*path;
    100 
    101 	/* Keep _CS_PATH in sync with execvp.c */
    102 
    103 	if (name == _CS_PATH) {
    104 		if (__xpg6 & _C99SUSv3_XPG6_sysconf_version)
    105 			path = "/usr/xpg6/bin:/usr/xpg4/bin:/usr/ccs/bin:"
    106 			    "/usr/bin:/opt/SUNWspro/bin";
    107 		else
    108 			path = "/usr/xpg4/bin:/usr/ccs/bin:/usr/bin:"
    109 			    "/opt/SUNWspro/bin";
    110 
    111 		conf_length = strlen(path) + 1;
    112 		if (length != 0) {
    113 			(void) strncpy(buf, path, length);
    114 			buf[length - 1] = '\0';
    115 		}
    116 		return (conf_length);
    117 	}
    118 	/*
    119 	 * Make sure others are known configuration parameters
    120 	 */
    121 	entry = (config *)default_conf;
    122 	for (i = 0; i < CS_ENTRY_COUNT; i++) {
    123 		if (name == entry->config_value) {
    124 			/*
    125 			 * Copy out the parameter from our tables.
    126 			 */
    127 			conf_length = strlen(entry->value) + 1;
    128 			if (length != 0) {
    129 				(void) strncpy(buf, entry->value, length);
    130 				buf[length - 1] = '\0';
    131 			}
    132 			return (conf_length);
    133 		}
    134 		entry++;
    135 	}
    136 
    137 	/* If the entry was not found in table return an error */
    138 	errno = EINVAL;
    139 	return ((size_t)0);
    140 }
    141