Changeset View
Changeset View
Standalone View
Standalone View
head/usr.bin/systat/fetch.c
Show First 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
void getsysctl(const char *name, void *ptr, size_t len) | void getsysctl(const char *name, void *ptr, size_t len) | ||||
{ | { | ||||
size_t nlen = len; | size_t nlen = len; | ||||
if (sysctlbyname(name, ptr, &nlen, NULL, 0) != 0) { | if (sysctlbyname(name, ptr, &nlen, NULL, 0) != 0) { | ||||
error("sysctl(%s...) failed: %s", name, | error("sysctl(%s...) failed: %s", name, | ||||
strerror(errno)); | strerror(errno)); | ||||
} | } | ||||
if (nlen != len) { | if (nlen != len) { | ||||
error("sysctl(%s...) expected %lu, got %lu", name, | error("sysctl(%s...) expected %zu, got %zu", name, len, nlen); | ||||
(unsigned long)len, (unsigned long)nlen); | |||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Read sysctl data with variable size. Try some times (with increasing | * Read sysctl data with variable size. Try some times (with increasing | ||||
* buffers), fail if still too small. | * buffers), fail if still too small. | ||||
* This is needed sysctls with possibly raplidly increasing data sizes, | * This is needed sysctls with possibly raplidly increasing data sizes, | ||||
* but imposes little overhead in the case of constant sizes. | * but imposes little overhead in the case of constant sizes. | ||||
* Returns NULL on error, or a pointer to freshly malloc()'ed memory that holds | * Returns NULL on error, or a pointer to freshly malloc()'ed memory that holds | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |