#include <pthread.h>
#include <stdio.h> // For FOPEN_MAX.
#include <sys/auxv.h>
+#include <sys/resource.h>
#include <sys/sysconf.h>
#include <sys/sysinfo.h>
#include <time.h>
return clock_getres(clock_id, NULL) == 0;
}
+static long __sysconf_rlimit(int resource) {
+ rlimit rl;
+ getrlimit(resource, &rl);
+ return rl.rlim_cur;
+}
+
long sysconf(int name) {
switch (name) {
case _SC_ARG_MAX: return ARG_MAX;
case _SC_BC_DIM_MAX: return _POSIX2_BC_DIM_MAX; // Minimum requirement.
case _SC_BC_SCALE_MAX: return _POSIX2_BC_SCALE_MAX; // Minimum requirement.
case _SC_BC_STRING_MAX: return _POSIX2_BC_STRING_MAX; // Minimum requirement.
- case _SC_CHILD_MAX: return CHILD_MAX;
+ case _SC_CHILD_MAX: return __sysconf_rlimit(RLIMIT_NPROC);
case _SC_CLK_TCK: return static_cast<long>(getauxval(AT_CLKTCK));
case _SC_COLL_WEIGHTS_MAX: return _POSIX2_COLL_WEIGHTS_MAX; // Minimum requirement.
case _SC_EXPR_NEST_MAX: return _POSIX2_EXPR_NEST_MAX; // Minimum requirement.
case _SC_LINE_MAX: return _POSIX2_LINE_MAX; // Minimum requirement.
case _SC_NGROUPS_MAX: return NGROUPS_MAX;
- case _SC_OPEN_MAX: return OPEN_MAX;
+ case _SC_OPEN_MAX: return __sysconf_rlimit(RLIMIT_NOFILE);
case _SC_PASS_MAX: return PASS_MAX;
case _SC_2_C_BIND: return _POSIX2_C_BIND;
case _SC_2_C_DEV: return _POSIX2_C_DEV;