xref: /csrg-svn/lib/libc/gen/sysconf.c (revision 59721)
1*59721Sbostic /*-
2*59721Sbostic  * Copyright (c) 1993 The Regents of the University of California.
3*59721Sbostic  * All rights reserved.
4*59721Sbostic  *
5*59721Sbostic  * This code is derived from software contributed to Berkeley by
6*59721Sbostic  * Sean Eric Fagan of Cygnus Support.
7*59721Sbostic  *
8*59721Sbostic  * %sccs.include.redist.c%
9*59721Sbostic  */
10*59721Sbostic 
11*59721Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*59721Sbostic static char sccsid[] = "@(#)sysconf.c	5.1 (Berkeley) 05/04/93";
13*59721Sbostic #endif /* LIBC_SCCS and not lint */
14*59721Sbostic 
15*59721Sbostic #include <sys/param.h>
16*59721Sbostic #include <sys/sysctl.h>
17*59721Sbostic 
18*59721Sbostic #include <errno.h>
19*59721Sbostic #include <unistd.h>
20*59721Sbostic 
21*59721Sbostic long
22*59721Sbostic sysconf(name)
23*59721Sbostic 	int name;
24*59721Sbostic {
25*59721Sbostic 	struct clockinfo clk;
26*59721Sbostic 	size_t len;
27*59721Sbostic 	int mib[2], value;
28*59721Sbostic 
29*59721Sbostic 	switch (name) {
30*59721Sbostic 	case _SC_ARG_MAX:
31*59721Sbostic 		mib[0] = CTL_KERN;
32*59721Sbostic 		mib[1] = KERN_ARGMAX;
33*59721Sbostic 		break;
34*59721Sbostic 	case _SC_CHILD_MAX:
35*59721Sbostic 		mib[0] = CTL_KERN;
36*59721Sbostic 		mib[1] = KERN_MAXPROC;
37*59721Sbostic 		break;
38*59721Sbostic 	case _SC_CLK_TCK:
39*59721Sbostic 		mib[0] = CTL_KERN;
40*59721Sbostic 		mib[1] = KERN_CLOCKRATE;
41*59721Sbostic 		len = sizeof(struct clockinfo);
42*59721Sbostic 		return (sysctl(mib, 2,
43*59721Sbostic 		    &clk, &len, NULL, 0) == -1 ? -1 : clk.hz);
44*59721Sbostic 	case _SC_NGROUPS_MAX:
45*59721Sbostic 		mib[0] = CTL_KERN;
46*59721Sbostic 		mib[1] = KERN_NGROUPS;
47*59721Sbostic 		break;
48*59721Sbostic 	case _SC_OPEN_MAX:
49*59721Sbostic 		mib[0] = CTL_KERN;
50*59721Sbostic 		mib[1] = KERN_MAXFILES;
51*59721Sbostic 		break;
52*59721Sbostic 	case _SC_JOB_CONTROL:
53*59721Sbostic 		mib[0] = CTL_KERN;
54*59721Sbostic 		mib[1] = KERN_JOB_CONTROL;
55*59721Sbostic 		break;
56*59721Sbostic 	case _SC_SAVED_IDS:
57*59721Sbostic 		mib[0] = CTL_KERN;
58*59721Sbostic 		mib[1] = KERN_SAVED_IDS;
59*59721Sbostic 		break;
60*59721Sbostic 	case _SC_VERSION:
61*59721Sbostic 		mib[0] = CTL_KERN;
62*59721Sbostic 		mib[1] = KERN_POSIX1;
63*59721Sbostic 		break;
64*59721Sbostic 	case _SC_BC_BASE_MAX:
65*59721Sbostic 		mib[0] = CTL_USER;
66*59721Sbostic 		mib[1] = USER_BC_BASE_MAX;
67*59721Sbostic 		break;
68*59721Sbostic 	case _SC_BC_DIM_MAX:
69*59721Sbostic 		mib[0] = CTL_USER;
70*59721Sbostic 		mib[1] = USER_BC_DIM_MAX;
71*59721Sbostic 		break;
72*59721Sbostic 	case _SC_BC_SCALE_MAX:
73*59721Sbostic 		mib[0] = CTL_USER;
74*59721Sbostic 		mib[1] = USER_BC_SCALE_MAX;
75*59721Sbostic 		break;
76*59721Sbostic 	case _SC_BC_STRING_MAX:
77*59721Sbostic 		mib[0] = CTL_USER;
78*59721Sbostic 		mib[1] = USER_BC_STRING_MAX;
79*59721Sbostic 		break;
80*59721Sbostic 	case _SC_COLL_WEIGHTS_MAX:
81*59721Sbostic 		mib[0] = CTL_USER;
82*59721Sbostic 		mib[1] = USER_COLL_WEIGHTS_MAX;
83*59721Sbostic 		break;
84*59721Sbostic 	case _SC_EXPR_NEST_MAX:
85*59721Sbostic 		mib[0] = CTL_USER;
86*59721Sbostic 		mib[1] = USER_EXPR_NEST_MAX;
87*59721Sbostic 		break;
88*59721Sbostic 	case _SC_LINE_MAX:
89*59721Sbostic 		mib[0] = CTL_USER;
90*59721Sbostic 		mib[1] = USER_LINE_MAX;
91*59721Sbostic 		break;
92*59721Sbostic 	case _SC_RE_DUP_MAX:
93*59721Sbostic 		mib[0] = CTL_USER;
94*59721Sbostic 		mib[1] = USER_RE_DUP_MAX;
95*59721Sbostic 		break;
96*59721Sbostic 	case _SC_2_VERSION:
97*59721Sbostic 		mib[0] = CTL_USER;
98*59721Sbostic 		mib[1] = USER_POSIX2_VERSION;
99*59721Sbostic 		break;
100*59721Sbostic 	case _SC_2_C_BIND:
101*59721Sbostic 		mib[0] = CTL_USER;
102*59721Sbostic 		mib[1] = USER_POSIX2_C_BIND;
103*59721Sbostic 		break;
104*59721Sbostic 	case _SC_2_C_DEV:
105*59721Sbostic 		mib[0] = CTL_USER;
106*59721Sbostic 		mib[1] = USER_POSIX2_C_DEV;
107*59721Sbostic 		break;
108*59721Sbostic 	case _SC_2_FORT_DEV:
109*59721Sbostic 		mib[0] = CTL_USER;
110*59721Sbostic 		mib[1] = USER_POSIX2_FORT_DEV;
111*59721Sbostic 		break;
112*59721Sbostic 	case _SC_2_FORT_RUN:
113*59721Sbostic 		mib[0] = CTL_USER;
114*59721Sbostic 		mib[1] = USER_POSIX2_FORT_RUN;
115*59721Sbostic 		break;
116*59721Sbostic 	case _SC_2_LOCALEDEF:
117*59721Sbostic 		mib[0] = CTL_USER;
118*59721Sbostic 		mib[1] = USER_POSIX2_LOCALEDEF;
119*59721Sbostic 		break;
120*59721Sbostic 	case _SC_2_SW_DEV:
121*59721Sbostic 		mib[0] = CTL_USER;
122*59721Sbostic 		mib[1] = USER_POSIX2_SW_DEV;
123*59721Sbostic 		break;
124*59721Sbostic 	default:
125*59721Sbostic 		errno = EINVAL;
126*59721Sbostic 		return (-1);
127*59721Sbostic 	}
128*59721Sbostic 	len = sizeof(value);
129*59721Sbostic 	return (sysctl(mib, 2, &value, &len, NULL, 0) == -1 ? -1 : value);
130*59721Sbostic }
131