From c4e917790ed17c3452e4a97e74fd3b7d60a004e0 Mon Sep 17 00:00:00 2001 From: Nicolas Cavallari Date: Wed, 8 Jun 2016 14:33:58 +0200 Subject: [PATCH] linux-core: fix uv_get_total/free_memory on uclibc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The _SC_PHYS_PAGES and _SC_AVPHYS_PAGES are not POSIX sysconf values, so the standart C libraries have no obligation to support it, even on Linux. Use the Linux sysinfo() system call instead. PR-URL: https://github.com/libuv/libuv/pull/901 Reviewed-By: Ben Noordhuis Reviewed-By: Colin Ihrig Reviewed-By: Saúl Ibarra Corretgé --- src/unix/linux-core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/unix/linux-core.c b/src/unix/linux-core.c index b48a1111..ae927b7e 100644 --- a/src/unix/linux-core.c +++ b/src/unix/linux-core.c @@ -484,12 +484,20 @@ int uv_exepath(char* buffer, size_t* size) { uint64_t uv_get_free_memory(void) { - return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_AVPHYS_PAGES); + struct sysinfo info; + + if (sysinfo(&info) == 0) + return (uint64_t) info.freeram * info.mem_unit; + return 0; } uint64_t uv_get_total_memory(void) { - return (uint64_t) sysconf(_SC_PAGESIZE) * sysconf(_SC_PHYS_PAGES); + struct sysinfo info; + + if (sysinfo(&info) == 0) + return (uint64_t) info.totalram * info.mem_unit; + return 0; }