summaryrefslogtreecommitdiff
path: root/lang/parrot/patches/patch-al
blob: 3028148262a62dab9097fcf8e008208cf84869d5 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
$NetBSD: patch-al,v 1.1 2010/11/22 12:11:38 he Exp $

Copy FreeBSD's sysmem, and s/freebsd/netbsd/.

--- config/gen/platform/netbsd/sysmem.c.orig 2010-11-18 10:41:13.000000000 +0100
+++ config/gen/platform/netbsd/sysmem.c	2010-11-13 17:50:25.000000000 +0100
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2010, Parrot Foundation.
+ */
+
+/*
+
+=head1 NAME
+
+config/gen/platform/netbsd/sysmem.c
+
+=head1 DESCRIPTION
+
+Get system memory information.
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+#include <sys/sysctl.h>
+#include <stdio.h>
+
+/*
+
+=item C<size_t Parrot_sysmem_amount(PARROT_INTERP)>
+
+Get information about available physical memory.
+
+=cut
+
+*/
+
+size_t
+Parrot_sysmem_amount(PARROT_INTERP)
+{
+    int           err = 0;
+    size_t        memsize = 0;
+    char         *err_msg;
+    unsigned long length = sizeof (memsize);
+
+    int selection[2] = { CTL_HW, HW_PHYSMEM };
+
+    err = sysctl(selection, 2, &memsize, &length, NULL, 0);
+
+    if (err) {
+        err_msg = strerror(err);
+        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_EXTERNAL_ERROR,
+                "sysctl failed: %s", err_msg);
+    }
+
+    return memsize;
+}
+
+/*
+
+=back
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */