summaryrefslogtreecommitdiff
path: root/src/legacy
diff options
context:
space:
mode:
Diffstat (limited to 'src/legacy')
-rw-r--r--src/legacy/getloadavg.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/legacy/getloadavg.c b/src/legacy/getloadavg.c
new file mode 100644
index 00000000..43a8c9e3
--- /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;
+}