From 151394174a7b0c59f77c7ec34ed6845f1cbbaac8 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Mon, 21 Jan 2019 19:08:16 +0100 Subject: use sysconf --- lavg/lavg.c | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/lavg/lavg.c b/lavg/lavg.c index ee5b1a2..693f5a1 100644 --- a/lavg/lavg.c +++ b/lavg/lavg.c @@ -15,16 +15,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifndef lint -static const char rcsid[] = "$Id$"; -#endif /* not lint */ - -#include -#include -#include #include #include #include +#include static const struct { char *name; @@ -39,29 +33,13 @@ static const struct { int factor[3] = { 2, 1, 1 }; -int -ncpu(void) -{ - int mib[2], n; - size_t len; - - mib[0] = CTL_HW; - mib[1] = HW_NCPU; - len = sizeof(n); - - if (sysctl(mib, 2, &n, &len, NULL, 0) == -1) - err(1, "sysctl"); - - return n; -} - int main(void) { double avg[3], threshold; int i, n, cpu; - cpu = ncpu(); + cpu = sysconf(_SC_NPROCESSORS_CONF); threshold = log(cpu) + 1; printf("Content-Type: text/html\n\n\n"); -- cgit v1.2.3