/
sysmem.c
69 lines (45 loc) · 976 Bytes
/
sysmem.c
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
/*
* Copyright (C) 2010, Parrot Foundation.
*/
/*
=head1 NAME
config/gen/platform/freebsd/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 cinoptions='\:2=2' :
*/