From 59a314fd82aefb99aea2e3956248a928f55fa5e4 Mon Sep 17 00:00:00 2001 From: reinelt Date: Fri, 30 Jan 2004 07:12:35 +0000 Subject: [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 --- plugin_loadavg.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) (limited to 'plugin_loadavg.c') 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 #include #include +#include +#include +#include +#include #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) { -- cgit v1.2.3