bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

physmem_total broken with musl libc


From: Natanael Copa
Subject: physmem_total broken with musl libc
Date: Tue, 15 Apr 2014 13:37:20 +0200

Hi,

It seems like physmem_total is broken with musl libc since
_SC_PHYS_PAGES is not implemented.

Would it be an idea to use sysinfo from  sys/sysinfo.h first and then
fallback to the current _SC_PHYS_PAGES * _SC_PAGESIZE?

Something like:

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])
 ])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]