From: Alexander Monakov Date: Tue, 24 Feb 2015 18:44:07 +0000 (+0300) Subject: getloadavg: use sysinfo() instead of /proc/loadavg X-Git-Tag: v1.1.7~35 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=20cbd607759038dca57f84ef7e7b5d44a3088574;p=oweals%2Fmusl.git getloadavg: use sysinfo() instead of /proc/loadavg Based on a patch by Szabolcs Nagy. --- diff --git a/src/legacy/getloadavg.c b/src/legacy/getloadavg.c index 43a8c9e3..ff06de0f 100644 --- a/src/legacy/getloadavg.c +++ b/src/legacy/getloadavg.c @@ -1,18 +1,14 @@ #define _GNU_SOURCE #include -#include -#include +#include int getloadavg(double *a, int n) { - int i; - double b[3]; - FILE *f = fopen("/proc/loadavg", "rbe"); - if (!f) return -1; - i = fscanf(f, "%lf %lf %lf", b, b+1, b+2); - fclose(f); - if (n > i) n = i; - if (n < 0) return -1; - memcpy(a, b, n * sizeof *a); + struct sysinfo si; + if (n <= 0) return n ? -1 : 0; + sysinfo(&si); + if (n > 3) n = 3; + for (int i=0; i