[PC-BSD Commits] r2054 - pcbsd/trunk/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Sun Jun 8 14:15:57 PDT 2008


Author: tim
Date: 2008-06-08 14:15:57 -0700 (Sun, 08 Jun 2008)
New Revision: 2054

Modified:
   pcbsd/trunk/libpcbsd/utils.cpp
   pcbsd/trunk/libpcbsd/utils.h
Log:
Added functions to library

Modified: pcbsd/trunk/libpcbsd/utils.cpp
===================================================================
--- pcbsd/trunk/libpcbsd/utils.cpp	2008-06-08 18:35:05 UTC (rev 2053)
+++ pcbsd/trunk/libpcbsd/utils.cpp	2008-06-08 21:15:57 UTC (rev 2054)
@@ -37,3 +37,24 @@
    result[len] = '\0';
    return QString(result);
 }
+
+int Utils::sysctlAsInt(QString sysctl)
+{
+   int result = 0;
+   size_t len = sizeof(result);
+   sysctlbyname(sysctl.ascii(), &result, &len, NULL, 0);
+   return result;
+}
+
+QString Utils::bytesToHumanReadable(float bytes)
+{
+   QString suffix[] = {"B", "KB", "MB", "GB", "TB"};
+   int i = 0;
+   while((bytes >= 1000) && (i < 4))
+   {
+      bytes = bytes / 1024;
+      i++;
+   }
+   QString result = QString::number(bytes, 'f', 0);
+   return result += suffix[i];
+}

Modified: pcbsd/trunk/libpcbsd/utils.h
===================================================================
--- pcbsd/trunk/libpcbsd/utils.h	2008-06-08 18:35:05 UTC (rev 2053)
+++ pcbsd/trunk/libpcbsd/utils.h	2008-06-08 21:15:57 UTC (rev 2054)
@@ -29,6 +29,8 @@
 {
 public:
    static QString sysctl(QString sysctl);
+   static int sysctlAsInt(QString sysctl);
+   static QString bytesToHumanReadable(float bytes);
 };
 
 #endif



More information about the Commits mailing list