Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
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/. */
8 #include <stdio.h>
9 #include "Hal.h"
11 namespace mozilla {
12 namespace hal_impl {
14 uint32_t
15 GetTotalSystemMemory()
16 {
17 static uint32_t sTotalMemory;
18 static bool sTotalMemoryObtained = false;
20 if (!sTotalMemoryObtained) {
21 sTotalMemoryObtained = true;
23 FILE* fd = fopen("/proc/meminfo", "r");
24 if (!fd) {
25 return 0;
26 }
28 int rv = fscanf(fd, "MemTotal: %i kB", &sTotalMemory);
30 if (fclose(fd) || rv != 1) {
31 return 0;
32 }
33 }
35 return sTotalMemory * 1024;
36 }
38 } // namespace hal_impl
39 } // namespace mozilla