From 200ee91f88ce69df6fb387a954021e0d31d1b354 Mon Sep 17 00:00:00 2001
From: Rolf Eike Beer <eike@sf-mail.de>
Date: Sat, 5 Jan 2013 15:29:28 +0100
Subject: [PATCH] SystemInformation: split HP-UX code out of QueryMemory()

Change-Id: Ibebc8eba54793dd3d6a94f5fd54b5939b4689f68
---
 SystemInformation.cxx | 65 ++++++++++++++++++++++++++-----------------
 1 file changed, 39 insertions(+), 26 deletions(-)

diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index 02d401c..7ca14d9 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -465,6 +465,7 @@ protected:
   bool QueryBSDProcessor();
 
   //For HP-UX
+  bool QueryHPUXMemory();
   bool QueryHPUXProcessor();
 
   //For Microsoft Windows
@@ -1311,6 +1312,8 @@ void SystemInformationImplementation::RunMemoryCheck()
   this->QueryBSDMemory();
 #elif defined(_WIN32)
   this->QueryWindowsMemory();
+#elif defined(__hpux)
+  this->QueryHPUXMemory();
 #else
   this->QueryMemory();
 #endif
@@ -3515,32 +3518,6 @@ int SystemInformationImplementation::QueryMemory()
     }
   fclose( fd );
   return 1;
-#elif defined(__hpux)
-  unsigned long tv=0;
-  unsigned long tp=0;
-  unsigned long av=0;
-  unsigned long ap=0;
-  struct pst_static pst;
-  struct pst_dynamic pdy;
-
-  unsigned long ps = 0;
-  if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1)
-    {
-    ps = pst.page_size;
-    tp =  pst.physical_memory *ps;
-    tv = (pst.physical_memory + pst.pst_maxmem) * ps;
-    if (pstat_getdynamic(&pdy, sizeof(pdy), (size_t) 1, 0) != -1)
-      {
-      ap = tp - pdy.psd_rm * ps;
-      av = tv - pdy.psd_vm;
-      this->TotalVirtualMemory = tv>>10>>10;
-      this->TotalPhysicalMemory = tp>>10>>10;
-      this->AvailableVirtualMemory = av>>10>>10;
-      this->AvailablePhysicalMemory = ap>>10>>10;
-      return 1;
-      }
-    }
-  return 0;
 #elif defined(_AIX)
   long c = sysconf(_SC_AIX_REALMEM);
   if (c <= 0)
@@ -4426,6 +4403,42 @@ bool SystemInformationImplementation::QueryBSDProcessor()
 #endif
 }
 
+bool SystemInformationImplementation::QueryHPUXMemory()
+{
+#if defined(__hpux)
+  unsigned long tv=0;
+  unsigned long tp=0;
+  unsigned long av=0;
+  unsigned long ap=0;
+  struct pst_static pst;
+  struct pst_dynamic pdy;
+
+  unsigned long ps = 0;
+  if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) == -1)
+    {
+    return false;
+    }
+
+  ps = pst.page_size;
+  tp =  pst.physical_memory *ps;
+  tv = (pst.physical_memory + pst.pst_maxmem) * ps;
+  if (pstat_getdynamic(&pdy, sizeof(pdy), (size_t) 1, 0) == -1)
+    {
+    return false;
+    }
+
+  ap = tp - pdy.psd_rm * ps;
+  av = tv - pdy.psd_vm;
+  this->TotalVirtualMemory = tv>>10>>10;
+  this->TotalPhysicalMemory = tp>>10>>10;
+  this->AvailableVirtualMemory = av>>10>>10;
+  this->AvailablePhysicalMemory = ap>>10>>10;
+  return true;
+#else
+  return false;
+#endif
+}
+
 bool SystemInformationImplementation::QueryHPUXProcessor()
 {
 #if defined(__hpux)
-- 
GitLab