vm: fix a null dereference on out-of-memory
[minix.git] / lib / libc / gen / minix / sysconf.c
blob45a9e7b13c47215badac6d9ac44c99ce6ad1ff86
1 /* sysconf.c POSIX 4.8.1
2 * long int sysconf(int name);
4 * POSIX allows some of the values in <limits.h> to be increased at
5 * run time. The sysconf() function allows such values to be checked
6 * at run time. MINIX does not use this facility - the run time
7 * limits are those given in <limits.h>.
8 */
9 #include <sys/cdefs.h>
10 #include "namespace.h"
12 #include <lib.h>
13 #include <unistd.h>
14 #include <time.h>
15 #include <stdio.h>
16 #include <paths.h>
18 #ifdef __weak_alias
19 __weak_alias(sysconf, __sysconf)
20 #endif
22 static u32_t get_hz(void)
24 FILE *fp;
25 u32_t hz;
26 int r;
28 if ((fp = fopen(_PATH_PROC "hz", "r")) != NULL)
30 r = fscanf(fp, "%u", &hz);
32 fclose(fp);
34 if (r == 1)
35 return hz;
38 return DEFAULT_HZ;
41 long int sysconf(name)
42 int name; /* property being inspected */
44 switch(name) {
45 case _SC_ARG_MAX:
46 return (long) ARG_MAX;
48 case _SC_CHILD_MAX:
49 return (long) CHILD_MAX;
51 case _SC_CLK_TCK:
52 return (long) get_hz();
54 case _SC_NGROUPS_MAX:
55 return (long) NGROUPS_MAX;
57 case _SC_OPEN_MAX:
58 return (long) OPEN_MAX;
60 case _SC_JOB_CONTROL:
61 return -1L; /* no job control */
63 case _SC_SAVED_IDS:
64 return -1L; /* no saved uid/gid */
66 case _SC_VERSION:
67 return (long) _POSIX_VERSION;
69 case _SC_STREAM_MAX:
70 return (long) STREAM_MAX;
72 case _SC_TZNAME_MAX:
73 return (long) TZNAME_MAX;
75 case _SC_PAGESIZE:
76 return getpagesize();
78 default:
79 errno = EINVAL;
80 return -1L;