summaryrefslogtreecommitdiff
path: root/lib/physmem.c
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-09-30 18:22:54 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-09-30 18:22:54 +0400
commit08bc9e01c274a01d107b348f921e1c74dd04bd3a (patch)
tree25348bff03c29d9dd6c6dd96bf82c7c9f9265ccf /lib/physmem.c
parentb9c7373f203ab77c58cb6b131f8b58236ea337a2 (diff)
parentc18578632fd3c9e513e613a86ba2b7c4ebee6c45 (diff)
downloadcoreutils-08bc9e01c274a01d107b348f921e1c74dd04bd3a.tar.gz
Merge tag 'upstream/8.23'
Upstream version 8.23
Diffstat (limited to 'lib/physmem.c')
-rw-r--r--lib/physmem.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/lib/physmem.c b/lib/physmem.c
index 26299361..d0989aa8 100644
--- a/lib/physmem.c
+++ b/lib/physmem.c
@@ -1,6 +1,6 @@
/* Calculate the size of physical memory.
- Copyright (C) 2000-2001, 2003, 2005-2006, 2009-2013 Free Software
+ Copyright (C) 2000-2001, 2003, 2005-2006, 2009-2014 Free Software
Foundation, Inc.
This program is free software: you can redistribute it and/or modify
@@ -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
@@ -90,6 +93,14 @@ physmem_total (void)
}
#endif
+#if HAVE_SYSINFO && HAVE_STRUCT_SYSINFO_MEM_UNIT
+ { /* This works on linux. */
+ struct sysinfo si;
+ if (sysinfo(&si) == 0)
+ return (double) si.totalram * si.mem_unit;
+ }
+#endif
+
#if HAVE_PSTAT_GETSTATIC
{ /* This works on hpux11. */
struct pst_static pss;
@@ -194,6 +205,14 @@ physmem_available (void)
}
#endif
+#if HAVE_SYSINFO && HAVE_STRUCT_SYSINFO_MEM_UNIT
+ { /* This works on linux. */
+ struct sysinfo si;
+ if (sysinfo(&si) == 0)
+ return ((double) si.freeram + si.bufferram) * si.mem_unit;
+ }
+#endif
+
#if HAVE_PSTAT_GETSTATIC && HAVE_PSTAT_GETDYNAMIC
{ /* This works on hpux11. */
struct pst_static pss;