Line data Source code
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 0 : GetTotalSystemMemory()
16 : {
17 : static uint32_t sTotalMemory;
18 : static bool sTotalMemoryObtained = false;
19 :
20 0 : if (!sTotalMemoryObtained) {
21 0 : sTotalMemoryObtained = true;
22 :
23 0 : FILE* fd = fopen("/proc/meminfo", "r");
24 0 : if (!fd) {
25 0 : return 0;
26 : }
27 :
28 0 : int rv = fscanf(fd, "MemTotal: %i kB", &sTotalMemory);
29 :
30 0 : if (fclose(fd) || rv != 1) {
31 0 : return 0;
32 : }
33 : }
34 :
35 0 : return sTotalMemory * 1024;
36 : }
37 :
38 : } // namespace hal_impl
39 9 : } // namespace mozilla
|