linux-core: fix uv_get_total/free_memory on uclibc

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 <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Nicolas Cavallari 2016-06-08 14:33:58 +02:00 committed by Saúl Ibarra Corretgé
parent 5af420669a
commit c4e917790e

View File

@ -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;
}