blob: 116f3d4de63b451976b9b7f0da800c828acba4e2 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001From 3498f488b27f90398d7c8d1d06aac5ab684370e8 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Mon, 14 Dec 2015 00:47:53 +0000
4Subject: [PATCH 09/36] util: bypass unimplemented _SC_PHYS_PAGES system
5 configuration API on uclibc
6
7Upstream-Status: Inappropriate [uclibc-specific]
8
9Signed-off-by: Khem Raj <raj.khem@gmail.com>
10---
11 src/basic/util.c | 15 +++++++++++++++
12 1 file changed, 15 insertions(+)
13
14diff --git a/src/basic/util.c b/src/basic/util.c
15index ea1bed7..fdaf340 100644
16--- a/src/basic/util.c
17+++ b/src/basic/util.c
18@@ -767,10 +767,25 @@ uint64_t physical_memory(void) {
19 /* We return this as uint64_t in case we are running as 32bit
20 * process on a 64bit kernel with huge amounts of memory */
21
22+#ifdef __UCLIBC__
23+ char line[128];
24+ FILE *f = fopen("/proc/meminfo", "r");
25+ if (f == NULL)
26+ return 0;
27+ while (!feof(f) && fgets(line, sizeof(line)-1, f)) {
28+ if (sscanf(line, "MemTotal: %li kB", &mem) == 1) {
29+ mem *= 1024;
30+ break;
31+ }
32+ }
33+ fclose(f);
34+ return (uint64_t) mem;
35+#else
36 mem = sysconf(_SC_PHYS_PAGES);
37 assert(mem > 0);
38
39 return (uint64_t) mem * (uint64_t) page_size();
40+#endif
41 }
42
43 int update_reboot_param_file(const char *param) {
44--
451.8.3.1
46