summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2007-04-14 13:06:57 +0000
committerpjd <pjd@FreeBSD.org>2007-04-14 13:06:57 +0000
commit6f429811a0127d028b4fddef3dc8ab09bc8dcc04 (patch)
tree44bf1b6778d9a95615ee43b03b5f0946e7e29a34
parent3f5535c193a2fb151d0be1666357d49244228889 (diff)
downloadFreeBSD-src-6f429811a0127d028b4fddef3dc8ab09bc8dcc04.zip
FreeBSD-src-6f429811a0127d028b4fddef3dc8ab09bc8dcc04.tar.gz
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.
-rw-r--r--lib/libc/gen/sysconf.c39
1 files changed, 18 insertions, 21 deletions
diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c
index 97593be..8ea61af 100644
--- a/lib/libc/gen/sysconf.c
+++ b/lib/libc/gen/sysconf.c
@@ -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 @@ do_NAME_MAX:
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);
}
OpenPOWER on IntegriCloud