$NetBSD: patch-aj,v 1.9 2007/04/10 15:53:16 joerg Exp $ --- routines/os_specific/getmemory.c.orig 2006-02-01 20:50:55.000000000 +0000 +++ routines/os_specific/getmemory.c @@ -9,6 +9,12 @@ http://lists.gnu.org/archive/html/bug-gn */ #include "getmemory.h" +#if defined(__NetBSD__) || defined(__DragonFly__) +#include +#include +#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0])) +#endif + int getfreememory() { #define kooctet 1024 @@ -69,6 +75,19 @@ int getfreememory() } #endif +#if defined(__NetBSD__) || defined(__DragonFly__) +#define MEMOK 1 + { /* This works on *bsd and darwin. */ + unsigned int usermem; + size_t len = sizeof usermem; + static int mib[2] = { CTL_HW, HW_USERMEM }; + + if (sysctl (mib, ARRAY_SIZE (mib), &usermem, &len, NULL, 0) == 0 + && len == sizeof (usermem)) + return (double) usermem; + } +#endif + #ifndef MEMOK /* Linux ,Solaris and others assumed*/ return (sysconf(_SC_AVPHYS_PAGES)*sysconf(_SC_PAGESIZE))/kooctet; @@ -134,6 +153,19 @@ int getmemorysize() } #endif +#if defined(__NetBSD__) || defined(__DragonFly__) +#define MEMOK 1 + { /* This works on *bsd and darwin. */ + unsigned int physmem; + size_t len = sizeof physmem; + static int mib[2] = { CTL_HW, HW_PHYSMEM }; + + if (sysctl (mib, ARRAY_SIZE (mib), &physmem, &len, NULL, 0) == 0 + && len == sizeof (physmem)) + return (double) physmem; + } +#endif + #ifndef MEMOK /* Linux ,Solaris and others */ return (sysconf(_SC_PHYS_PAGES)*sysconf(_SC_PAGESIZE))/kooctet;