Cleanup sysconf(3) a bit. sysconf(3) assumes in some places it operates
on int, but in fact it should operate on long. - Introduce 'lvalue' variable, which is long. - Fix _SC_XOPEN_SHM for 64bit archs. - Fix _SC_PHYS_PAGES for 64bit archs. Reported by: simokawa - Use lvalue for pathconf(3), as it returns long. - Cast value explicitly to long on return.
This commit is contained in:
parent
e774c513f0
commit
e42e8df28f
@ -73,13 +73,10 @@ sysconf(name)
|
||||
struct rlimit rl;
|
||||
size_t len;
|
||||
int mib[2], sverrno, value;
|
||||
long defaultresult;
|
||||
long lvalue, defaultresult;
|
||||
const char *path;
|
||||
const char *sname;
|
||||
|
||||
len = sizeof(value);
|
||||
defaultresult = -1;
|
||||
sname = NULL;
|
||||
|
||||
switch (name) {
|
||||
case _SC_ARG_MAX:
|
||||
@ -168,11 +165,11 @@ sysconf(name)
|
||||
do_NAME_MAX:
|
||||
sverrno = errno;
|
||||
errno = 0;
|
||||
value = pathconf(path, _PC_NAME_MAX);
|
||||
if (value == -1 && errno != 0)
|
||||
lvalue = pathconf(path, _PC_NAME_MAX);
|
||||
if (lvalue == -1 && errno != 0)
|
||||
return (-1);
|
||||
errno = sverrno;
|
||||
return (value);
|
||||
return (lvalue);
|
||||
|
||||
case _SC_ASYNCHRONOUS_IO:
|
||||
#if _POSIX_ASYNCHRONOUS_IO == 0
|
||||
@ -295,12 +292,13 @@ sysconf(name)
|
||||
case _SC_TIMER_MAX:
|
||||
mib[0] = CTL_P1003_1B;
|
||||
mib[1] = CTL_P1003_1B_TIMER_MAX;
|
||||
|
||||
yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
||||
yesno:
|
||||
len = sizeof(value);
|
||||
if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
||||
return (-1);
|
||||
if (value == 0)
|
||||
return (defaultresult);
|
||||
return (value);
|
||||
return ((long)value);
|
||||
|
||||
case _SC_2_PBS:
|
||||
case _SC_2_PBS_ACCOUNTING:
|
||||
@ -528,8 +526,9 @@ yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
||||
return (_XOPEN_REALTIME_THREADS);
|
||||
#endif
|
||||
case _SC_XOPEN_SHM:
|
||||
len = sizeof(lvalue);
|
||||
sverrno = errno;
|
||||
if (sysctlbyname("kern.ipc.shmmin", &value, &len, NULL,
|
||||
if (sysctlbyname("kern.ipc.shmmin", &lvalue, &len, NULL,
|
||||
0) == -1) {
|
||||
errno = sverrno;
|
||||
return (-1);
|
||||
@ -574,20 +573,18 @@ yesno: if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
||||
|
||||
#ifdef _SC_PHYS_PAGES
|
||||
case _SC_PHYS_PAGES:
|
||||
sname = "hw.availpages";
|
||||
break;
|
||||
len = sizeof(lvalue);
|
||||
if (sysctlbyname("hw.availpages", &lvalue, &len, NULL, 0) == -1)
|
||||
return (-1);
|
||||
return (lvalue);
|
||||
#endif
|
||||
|
||||
default:
|
||||
errno = EINVAL;
|
||||
return (-1);
|
||||
}
|
||||
if (sname == NULL) {
|
||||
if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
||||
value = -1;
|
||||
} else {
|
||||
if (sysctlbyname(sname, &value, &len, NULL, 0) == -1)
|
||||
value = -1;
|
||||
}
|
||||
return (value);
|
||||
len = sizeof(value);
|
||||
if (sysctl(mib, 2, &value, &len, NULL, 0) == -1)
|
||||
value = -1;
|
||||
return ((long)value);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user