summaryrefslogtreecommitdiff
path: root/loadav.c
diff options
context:
space:
mode:
Diffstat (limited to 'loadav.c')
-rw-r--r--loadav.c41
1 files changed, 33 insertions, 8 deletions
diff --git a/loadav.c b/loadav.c
index 82bf176..0417a7c 100644
--- a/loadav.c
+++ b/loadav.c
@@ -1,4 +1,4 @@
-/* Copyright (c) 1993
+/* Copyright (c) 1993-2002
* Juergen Weigert (jnweiger@immd4.informatik.uni-erlangen.de)
* Michael Schroeder (mlschroe@immd4.informatik.uni-erlangen.de)
* Copyright (c) 1987 Oliver Laumann
@@ -72,15 +72,42 @@ static int
GetLoadav()
{
FILE *fp;
- double d[3];
+ char buf[128], *s;
int i;
+ double d, e;
if ((fp = secfopen("/proc/loadavg", "r")) == NULL)
return 0;
- fscanf(fp, "%lf %lf %lf\n", d, d + 1, d + 2);
+ *buf = 0;
+ fgets(buf, sizeof(buf), fp);
fclose(fp);
+ /* can't use fscanf because the decimal point symbol depends on
+ * the locale but the kernel uses always '.'.
+ */
+ s = buf;
for (i = 0; i < (LOADAV_NUM > 3 ? 3 : LOADAV_NUM); i++)
- loadav[i] = d[i];
+ {
+ d = e = 0;
+ while(*s == ' ')
+ s++;
+ if (*s == 0)
+ break;
+ for(;;)
+ {
+ if (*s == '.')
+ e = 1;
+ else if (*s >= '0' && *s <= '9')
+ {
+ d = d * 10 + (*s - '0');
+ if (e)
+ e *= 10;
+ }
+ else
+ break;
+ s++;
+ }
+ loadav[i] = e ? d / e : d;
+ }
return i;
}
#endif /* linux */
@@ -250,10 +277,8 @@ GetLoadav()
extern int nlist __P((char *, struct nlist *));
# endif
-#ifdef __sgi
-# if _MIPS_SZLONG == 64 || (defined(_MIPS_ISA) && _MIPS_ISA > 2)
-# define nlist nlist64
-# endif
+#ifdef LOADAV_USE_NLIST64
+# define nlist nlist64
#endif
static struct nlist nl[2];