Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From b45ea3bfd6635744c8a6b74d0ac701b44bb1d294 Mon Sep 17 00:00:00 2001 |
| 2 | From: Khem Raj <raj.khem@gmail.com> |
| 3 | Date: Fri, 20 Feb 2015 05:19:37 +0000 |
| 4 | Subject: [PATCH 08/11] util: bypass unimplemented _SC_PHYS_PAGES system |
| 5 | configuration API on uclibc |
| 6 | |
| 7 | Upstream-Status: Inappropriate [uclibc-specific] |
| 8 | |
| 9 | Signed-off-by: Khem Raj <raj.khem@gmail.com> |
| 10 | --- |
| 11 | src/basic/util.c | 15 +++++++++++++++ |
| 12 | 1 file changed, 15 insertions(+) |
| 13 | |
| 14 | diff --git a/src/basic/util.c b/src/basic/util.c |
| 15 | index 72f4665..cbbe3b1 100644 |
| 16 | --- a/src/basic/util.c |
| 17 | +++ b/src/basic/util.c |
| 18 | @@ -6793,10 +6793,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: %l 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 | void hexdump(FILE *f, const void *p, size_t s) { |
| 44 | -- |
| 45 | 2.1.4 |
| 46 | |