summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-02-15 09:05:16 +0000
committerJim Meyering <jim@meyering.net>2003-02-15 09:05:16 +0000
commitbdf738b1a1639fcd156b736d2ecc96a6f7b078d1 (patch)
tree463c9a2bc638d01964bddefb18c457c26de9adf0 /lib
parent5aeb13149ef9fb298bfabdc06e8752fb4ad50a8d (diff)
downloadcoreutils-bdf738b1a1639fcd156b736d2ecc96a6f7b078d1.tar.xz
Add Irix6 support to physmem.c.
(irix_sysget): New function. (IRIX_SYSGET_TOTAL, IRIX_SYSGET_AVAILABLE): New macros. (physmem_total, physmem_available): Use them.
Diffstat (limited to 'lib')
-rw-r--r--lib/physmem.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/lib/physmem.c b/lib/physmem.c
index 4219c7011..31436c993 100644
--- a/lib/physmem.c
+++ b/lib/physmem.c
@@ -1,5 +1,5 @@
/* Calculate the size of physical memory.
- Copyright 2000, 2001 Free Software Foundation, Inc.
+ Copyright 2000, 2001, 2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,7 +15,7 @@
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
-/* Written by Paul Eggert. */
+/* Written by Paul Eggert and Jim Meyering. */
#if HAVE_CONFIG_H
# include <config.h>
@@ -31,6 +31,42 @@
# include <sys/pstat.h>
#endif
+#if HAVE_SYSGET && HAVE_SYS_SYSGET_H && HAVE_SYS_SYSINFO_H && SGT_COOKIE_INIT
+# include <sys/types.h>
+# include <sys/sysget.h>
+# include <sys/sysinfo.h>
+
+# define IRIX_SYSGET_TOTAL \
+ do { double tot; if (irix_sysget (&tot, NULL) == 0) return tot; } while (0)
+# define IRIX_SYSGET_AVAILABLE \
+ do { double fr; if (irix_sysget (NULL, &fr) == 0) return fr; } while (0)
+
+/* If TOTAL is non-NULL, set *TOTAL to the number of bytes of physical memory.
+ If AVAIL is non-NULL, set *AVAIL to the number of bytes of available memory.
+ Return nonzero immediately if sysget fails.
+ Otherwise, set the requested value(s) and return zero. */
+static int
+irix_sysget (double *total, double *avail)
+{
+ nodeinfo_t buf;
+ sgt_cookie_t cookie;
+
+ SGT_COOKIE_INIT (&cookie);
+ if (sysget (SGT_NODE_INFO, (char *) &buf, sizeof buf, SGT_READ, &cookie)
+ != sizeof buf)
+ return 1;
+
+ if (total)
+ *total = buf.totalmem;
+ if (avail)
+ *avail = buf.freemem;
+ return 0;
+}
+#else
+# define IRIX_SYSGET_TOTAL
+# define IRIX_SYSGET_AVAILABLE
+#endif
+
/* Return the total amount of physical memory. */
double
physmem_total (void)
@@ -57,6 +93,8 @@ physmem_total (void)
}
#endif
+ IRIX_SYSGET_TOTAL;
+
/* Guess 64 MB. It's probably an older host, so guess small. */
return 64 * 1024 * 1024;
}
@@ -89,6 +127,8 @@ physmem_available (void)
}
#endif
+ IRIX_SYSGET_AVAILABLE;
+
/* Guess 25% of physical memory. */
return physmem_total () / 4;
}