summaryrefslogtreecommitdiff
path: root/math/scilab/patches/patch-aj
blob: 9d9e61ee8c0011b39d99b5de729a18d7f8054456 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
$NetBSD: patch-aj,v 1.8 2007/03/23 22:08:57 dmcmahill 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__)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#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__)
+#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__)
+#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;