]> granicus.if.org Git - fcron/commitdiff
modified for fcron
authorthib <thib>
Tue, 12 Sep 2000 19:54:02 +0000 (19:54 +0000)
committerthib <thib>
Tue, 12 Sep 2000 19:54:02 +0000 (19:54 +0000)
(return the num of values read + use error_e() )

getloadavg.c

index e9ec49f54458866c3351e37ede1a7509ea241234..3eba64378815b85e269a2945af964a4c6c34c41c 100644 (file)
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
-#include "config.h"
+#include "global.h"
 
 #define _POSIX_SOURCE 1
 
-/* System Headers */
-
-#include <stdio.h>
-
 /* Local headers */
 
 #include "getloadavg.h"
 
-/* File scope variables */
-
-static char rcsid[] = "$Id: getloadavg.c,v 1.1 2000-09-12 16:40:42 thib Exp $";
-
 /* Global functions */
 
 int
 getloadavg(double *result, int n)
-/* return the current load average as a floating point number, or <0 for
- * error
+/* return the current load average as a floating point number,
+ * the number of load averages read, or <0 for error
  */
 {
     FILE *fp;
@@ -48,8 +40,11 @@ getloadavg(double *result, int n)
     if (n > 3)
        n = 3;
 
-    if ((fp = fopen(PROC "/loadavg", "r")) == NULL)
+    if ((fp = fopen(PROC "/loadavg", "r")) == NULL) {
+       error_e("could not open '"PROC"/loadavg'"
+               " (make sure procfs is mounted)");
        i = -1;
+    }
     else {
        for (i = 0; i < n; i++) {
            if (fscanf(fp, "%lf", result) != 1)
@@ -59,5 +54,5 @@ getloadavg(double *result, int n)
     }
   end:
     fclose(fp);
-    return i;
+    return (i<0) ? i : i+1;
 }