1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

Use sysctl() != -1 instead of !sysctl() to check if

the function call succeeded.

NetBSD 4.0 returns positive values on success, but
NetBSD Current and FreeBSD return zero. OpenBSD's
man page doesn't tell what sysctl() returns on
success. All these BSDs return -1 on error.

Thanks to Robert Elz and Thomas Klausner.
This commit is contained in:
Lasse Collin 2009-09-05 01:20:29 +03:00
parent 173368911c
commit 60ccb80c9c
2 changed files with 2 additions and 2 deletions

View file

@ -40,7 +40,7 @@ cpucores(void)
int name[2] = { CTL_HW, HW_NCPU };
int cpus;
size_t cpus_size = sizeof(cpus);
if (!sysctl(name, 2, &cpus, &cpus_size, NULL, 0)
if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1
&& cpus_size == sizeof(cpus) && cpus > 0)
ret = (uint32_t)(cpus);
#endif

View file

@ -104,7 +104,7 @@ physmem(void)
uint64_t u64;
} mem;
size_t mem_ptr_size = sizeof(mem.u64);
if (!sysctl(name, 2, &mem.u64, &mem_ptr_size, NULL, 0)) {
if (sysctl(name, 2, &mem.u64, &mem_ptr_size, NULL, 0) != -1) {
// IIRC, 64-bit "return value" is possible on some 64-bit
// BSD systems even with HW_PHYSMEM (instead of HW_PHYSMEM64),
// so support both.