|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * vim: sw=2 ts=8 et : |
|
3 */ |
|
4 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
5 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
6 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
7 |
|
8 #include <stdio.h> |
|
9 #include "Hal.h" |
|
10 |
|
11 namespace mozilla { |
|
12 namespace hal_impl { |
|
13 |
|
14 uint32_t |
|
15 GetTotalSystemMemory() |
|
16 { |
|
17 static uint32_t sTotalMemory; |
|
18 static bool sTotalMemoryObtained = false; |
|
19 |
|
20 if (!sTotalMemoryObtained) { |
|
21 sTotalMemoryObtained = true; |
|
22 |
|
23 FILE* fd = fopen("/proc/meminfo", "r"); |
|
24 if (!fd) { |
|
25 return 0; |
|
26 } |
|
27 |
|
28 int rv = fscanf(fd, "MemTotal: %i kB", &sTotalMemory); |
|
29 |
|
30 if (fclose(fd) || rv != 1) { |
|
31 return 0; |
|
32 } |
|
33 } |
|
34 |
|
35 return sTotalMemory * 1024; |
|
36 } |
|
37 |
|
38 } // namespace hal_impl |
|
39 } // namespace mozilla |