Add Irix6 support to physmem.c.

(irix_sysget): New function.
(IRIX_SYSGET_TOTAL, IRIX_SYSGET_AVAILABLE): New macros.
(physmem_total, physmem_available): Use them.
This commit is contained in:
Jim Meyering committed 2003-02-15 09:05:16 +00:00
1 parent 5aeb13149e
commit bdf738b1a1
1 file changed
+42 -2
+42 -2
View File
@@ -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;
}