summaryrefslogtreecommitdiff
path: root/lib/physmem.c
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2014-09-30 18:22:48 +0400
committerIgor Pashev <pashev.igor@gmail.com>2014-09-30 18:22:48 +0400
commitc18578632fd3c9e513e613a86ba2b7c4ebee6c45 (patch)
tree377f4d4e3f0a6471a5012126078fcd97f4c67242 /lib/physmem.c
parent974ab3dd887985e3aa347f3c6521f819296396a0 (diff)
downloadcoreutils-c18578632fd3c9e513e613a86ba2b7c4ebee6c45.tar.gz
Imported Upstream version 8.23upstream/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;