]> code.delx.au - gnu-emacs/blobdiff - src/getloadavg.c
(start_of_text): Don't define #ifdef HAVE_TEXT_START.
[gnu-emacs] / src / getloadavg.c
index ff868c2dafc504fb764fa49d8c25a8d600bd8015..03b4de0239e7861639fb9ae05c3fb67ea33f7cb0 100644 (file)
@@ -51,6 +51,7 @@
    VMS
    __linux__                   Linux: assumes /proc filesystem mounted.
                                Support from Michael K. Johnson.
+   __NetBSD__                  NetBSD: assumes /kern filesystem mounted.
 
    In addition, to avoid nesting many #ifdefs, we internally set
    LDAV_DONE to indicate that the load average has been computed.
 
 
 #ifdef HAVE_CONFIG_H
+#if defined (emacs) || defined (CONFIG_BROKETS)
+/* We use <config.h> instead of "config.h" so that a compilation
+   using -I. -I$srcdir will use ./config.h rather than $srcdir/config.h
+   (which it would do because it found this file in $srcdir).  */
+#include <config.h>
+#else
 #include "config.h"
 #endif
+#endif
+
+
+/* Exclude all the code except the test program at the end
+   if the system has its own `getloadavg' function.  */
+
+#ifndef HAVE_GETLOADAVG
+
 
 /* The existing Emacs configuration files define a macro called
    LOAD_AVE_CVT, which accepts a value of type LOAD_AVE_TYPE, and
 
 #endif /* No LOAD_AVE_TYPE.  */
 
+#ifdef OSF_ALPHA
+/* <sys/param.h> defines an incorrect value for FSCALE on Alpha OSF/1,
+   according to ghazi@noc.rutgers.edu.  */
+#undef FSCALE
+#define FSCALE 1024.0
+#endif
+
+
 #ifndef        FSCALE
 
 /* SunOS and some others define FSCALE in sys/param.h.  */
@@ -489,6 +512,35 @@ getloadavg (loadavg, nelem)
 
 #endif /* __linux__ */
 
+#if !defined (LDAV_DONE) && defined (__NetBSD__)
+#define LDAV_DONE
+#undef LOAD_AVE_TYPE
+
+#ifndef NETBSD_LDAV_FILE
+#define NETBSD_LDAV_FILE "/kern/loadavg"
+#endif
+
+  unsigned long int load_ave[3], scale;
+  int count;
+  FILE *fp;
+
+  fp = fopen (NETBSD_LDAV_FILE, "r");
+  if (fp == NULL)
+    return -1;
+  count = fscanf (fp, "%lu %lu %lu %lu\n",
+                 &load_ave[0], &load_ave[1], &load_ave[2],
+                 &scale);
+  (void) fclose (fp);
+  if (count != 4)
+    return -1;
+
+  for (elem = 0; elem < nelem; elem++)
+    loadavg[elem] = (double) load_ave[elem] / (double) scale;
+
+  return elem;
+
+#endif /* __NetBSD__ */
+
 #if !defined (LDAV_DONE) && defined (NeXT)
 #define LDAV_DONE
   /* The NeXT code was adapted from iscreen 3.2.  */
@@ -798,6 +850,8 @@ getloadavg (loadavg, nelem)
   return -1;
 #endif
 }
+
+#endif /* ! HAVE_GETLOADAVG */
 \f
 #ifdef TEST
 void