aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_loadavg.c
diff options
context:
space:
mode:
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-30 07:12:35 +0000
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>2004-01-30 07:12:35 +0000
commit59a314fd82aefb99aea2e3956248a928f55fa5e4 (patch)
tree9a58587d75c2e4334d8ce18f0a08858939920f1d /plugin_loadavg.c
parent34f02389e3006b036d679f1ff1dd997c6f9f9f08 (diff)
downloadlcd4linux-59a314fd82aefb99aea2e3956248a928f55fa5e4.tar.gz
[lcd4linux @ 2004-01-30 07:12:35 by reinelt]
HD44780 busy-flag support from Martin Hejl loadavg() uClibc replacement from Martin Heyl round() uClibc replacement from Martin Hejl warning in i2c_sensors fixed [ git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@347 3ae390bd-cb1e-0410-b409-cd5a39f66f1f
Diffstat (limited to 'plugin_loadavg.c')
-rw-r--r--plugin_loadavg.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/plugin_loadavg.c b/plugin_loadavg.c
index e88baaa..3160122 100644
--- a/plugin_loadavg.c
+++ b/plugin_loadavg.c
@@ -1,4 +1,4 @@
-/* $Id: plugin_loadavg.c,v 1.2 2004/01/29 04:40:02 reinelt Exp $
+/* $Id: plugin_loadavg.c,v 1.3 2004/01/30 07:12:35 reinelt Exp $
*
* plugin for load average
*
@@ -23,6 +23,13 @@
*
*
* $Log: plugin_loadavg.c,v $
+ * Revision 1.3 2004/01/30 07:12:35 reinelt
+ * HD44780 busy-flag support from Martin Hejl
+ * loadavg() uClibc replacement from Martin Heyl
+ * round() uClibc replacement from Martin Hejl
+ * warning in i2c_sensors fixed
+ * [
+ *
* Revision 1.2 2004/01/29 04:40:02 reinelt
* every .c file includes "config.h" now
*
@@ -49,10 +56,51 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
#include "debug.h"
#include "plugin.h"
+#ifndef HAVE_GETLOADAVG
+
+int getloadavg (double loadavg[], int nelem)
+{
+ static int fd=-2;
+ char buf[65], *p;
+ ssize_t nread;
+ int i;
+
+ if (fd==-2) fd = open ("/proc/loadavg", O_RDONLY);
+ if (fd < 0) return -1;
+
+ lseek(fd,0,SEEK_SET);
+ nread = read (fd, buf, sizeof buf - 1);
+ //close (fd);
+
+ if (nread < 0) return -1;
+ buf[nread - 1] = '\0';
+
+ if (nelem > 3) nelem = 3;
+ p = buf;
+ for (i = 0; i < nelem; ++i) {
+ char *endp;
+ loadavg[i] = strtod (p, &endp);
+ if (endp == NULL || endp == p)
+ /* This should not happen. The format of /proc/loadavg
+ must have changed. Don't return with what we have,
+ signal an error. */
+ return -1;
+ p = endp;
+ }
+
+ return i;
+}
+
+#endif
+
static void my_loadavg (RESULT *result, RESULT *arg1)
{