From: Jim Meyering Date: Sat, 15 Feb 2003 09:05:16 +0000 (+0000) Subject: Add Irix6 support to physmem.c. X-Git-Tag: v4.5.8~115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdf738b1a1639fcd156b736d2ecc96a6f7b078d1;p=thirdparty%2Fcoreutils.git Add Irix6 support to physmem.c. (irix_sysget): New function. (IRIX_SYSGET_TOTAL, IRIX_SYSGET_AVAILABLE): New macros. (physmem_total, physmem_available): Use them. --- diff --git a/lib/physmem.c b/lib/physmem.c index 4219c7011b..31436c993d 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 @@ -31,6 +31,42 @@ # include #endif +#if HAVE_SYSGET && HAVE_SYS_SYSGET_H && HAVE_SYS_SYSINFO_H && SGT_COOKIE_INIT +# include +# include +# include + +# 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; }