diff options
author | Szabolcs Nagy <nsz@port70.net> | 2013-11-21 01:59:43 +0000 |
---|---|---|
committer | Szabolcs Nagy <nsz@port70.net> | 2013-11-21 01:59:43 +0000 |
commit | a516077feba96ec24d1ca8a9cbb8490bfdd066f1 (patch) | |
tree | 829547bd11df1e93f1d29ef46d2b24467a5cb41d /src/legacy | |
parent | ceb0ed9cf96d90e613a2c55a84ac0c8172fc7f10 (diff) | |
download | musl-a516077feba96ec24d1ca8a9cbb8490bfdd066f1.zip musl-a516077feba96ec24d1ca8a9cbb8490bfdd066f1.tar.gz musl-a516077feba96ec24d1ca8a9cbb8490bfdd066f1.tar.bz2 |
add legacy getloadavg api
Diffstat (limited to 'src/legacy')
-rw-r--r-- | src/legacy/getloadavg.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/legacy/getloadavg.c b/src/legacy/getloadavg.c new file mode 100644 index 0000000..43a8c9e --- /dev/null +++ b/src/legacy/getloadavg.c @@ -0,0 +1,18 @@ +#define _GNU_SOURCE +#include <stdlib.h> +#include <stdio.h> +#include <string.h> + +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); + return n; +} |