* lib/physmem.c (physmem_total): Some systems like musl libc does not (yet) support _SC_PHYS_PAGES. Use the linux syscall sysinfo first and fallback to sysconf with _SC_PHYS_PAGES and _SC_PAGESIZE.
Signed-off-by: Natanael Copa <nc...@alpinelinux.org> --- lib/physmem.c | 13 ++++++++++++- m4/physmem.m4 | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/physmem.c b/lib/physmem.c index 7a67fb3..1e5e2f7 100644 --- a/lib/physmem.c +++ b/lib/physmem.c @@ -32,8 +32,11 @@ # include <sys/sysmp.h> #endif -#if HAVE_SYS_SYSINFO_H && HAVE_MACHINE_HAL_SYSINFO_H +#if HAVE_SYS_SYSINFO_H # include <sys/sysinfo.h> +#endif + +#if HAVE_MACHINE_HAL_SYSINFO_H # include <machine/hal_sysinfo.h> #endif @@ -81,6 +84,14 @@ typedef WINBOOL (WINAPI *PFN_MS_EX) (lMEMORYSTATUSEX*); double physmem_total (void) { +#if HAVE_SYSINFO + { /* This works on linux */ + struct sysinfo si; + if (sysinfo(&si) == 0) + return si.totalram; + } +#endif + #if defined _SC_PHYS_PAGES && defined _SC_PAGESIZE { /* This works on linux-gnu, solaris2 and cygwin. */ double pages = sysconf (_SC_PHYS_PAGES); diff --git a/m4/physmem.m4 b/m4/physmem.m4 index ff3d268..1fe3254 100644 --- a/m4/physmem.m4 +++ b/m4/physmem.m4 @@ -40,6 +40,6 @@ AC_DEFUN([gl_PHYSMEM], #endif ]) - AC_CHECK_FUNCS([pstat_getstatic pstat_getdynamic sysmp getsysinfo sysctl table]) + AC_CHECK_FUNCS([pstat_getstatic pstat_getdynamic sysmp getsysinfo sysctl table sysinfo]) AC_REQUIRE([gl_SYS__SYSTEM_CONFIGURATION]) ]) -- 1.9.2