am c2085138
: Merge "Fix sysconf for _SC_CHILD_MAX and _SC_OPEN_MAX."
* commit 'c20851380cf5466a8bc422e7c26d3868a95423a9': Fix sysconf for _SC_CHILD_MAX and _SC_OPEN_MAX.
This commit is contained in:
commit
5a9734920c
1 changed files with 9 additions and 2 deletions
|
@ -33,6 +33,7 @@
|
|||
#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>
|
||||
|
@ -50,6 +51,12 @@ static bool __sysconf_has_clock(clockid_t clock_id) {
|
|||
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;
|
||||
|
@ -57,13 +64,13 @@ long sysconf(int name) {
|
|||
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;
|
||||
|
|
Loading…
Reference in a new issue