diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2008-09-20 18:06:42 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2008-09-20 18:06:42 +0200 |
commit | 84f69d7aacef531c0ad809d7511c7ab7bce7469c (patch) | |
tree | 5e2aad8ec1c4d577d5bf15aa37560d3f14578d21 /src/Common/Backends | |
parent | 89551ddfc2879530981eba3db9ab857b88409ad8 (diff) | |
download | mad-84f69d7aacef531c0ad809d7511c7ab7bce7469c.tar mad-84f69d7aacef531c0ad809d7511c7ab7bce7469c.zip |
/proc/meminfo ohne regul?re Ausdr?cke verarbeiten
Diffstat (limited to 'src/Common/Backends')
-rw-r--r-- | src/Common/Backends/Makefile.in | 2 | ||||
-rw-r--r-- | src/Common/Backends/SystemBackendProc.cpp | 29 |
2 files changed, 14 insertions, 17 deletions
diff --git a/src/Common/Backends/Makefile.in b/src/Common/Backends/Makefile.in index d943c5e..f8f56a7 100644 --- a/src/Common/Backends/Makefile.in +++ b/src/Common/Backends/Makefile.in @@ -122,8 +122,6 @@ PACKAGE_STRING = @PACKAGE_STRING@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ PACKAGE_VERSION = @PACKAGE_VERSION@ PATH_SEPARATOR = @PATH_SEPARATOR@ -PCRECPP_CFLAGS = @PCRECPP_CFLAGS@ -PCRECPP_LIBS = @PCRECPP_LIBS@ PKG_CONFIG = @PKG_CONFIG@ RANLIB = @RANLIB@ READLINE_LIBS = @READLINE_LIBS@ diff --git a/src/Common/Backends/SystemBackendProc.cpp b/src/Common/Backends/SystemBackendProc.cpp index 51e14f8..e8c7357 100644 --- a/src/Common/Backends/SystemBackendProc.cpp +++ b/src/Common/Backends/SystemBackendProc.cpp @@ -19,8 +19,8 @@ #include "SystemBackendProc.h" -#include <pcrecpp.h> #include <cstdio> +#include <cstring> namespace Mad { namespace Common { @@ -58,26 +58,25 @@ SystemBackend::MemoryInfo SystemBackendProc::getMemoryInfo() { if(!meminfoFile.good()) return memInfo; - pcrecpp::RE re("(.+):\\s*(\\d+).*"); - while(!meminfoFile.eof() && meminfoFile.good()) { std::string line; std::getline(meminfoFile, line); - std::string name; + char *name = new char[line.length()+1]; // is always long enough unsigned long value; - if(!re.FullMatch(line, &name, &value)) - continue; - - if(name == "MemTotal") - memInfo.totalMem = value; - else if(name == "MemFree") - memInfo.freeMem = value; - else if(name == "SwapTotal") - memInfo.totalSwap = value; - else if(name == "SwapFree") - memInfo.freeSwap = value; + if(std::sscanf(line.c_str(), "%s %lu", name, &value) == 2) { + if(std::strcmp(name, "MemTotal:") == 0) + memInfo.totalMem = value; + else if(std::strcmp(name, "MemFree:") == 0) + memInfo.freeMem = value; + else if(std::strcmp(name, "SwapTotal:") == 0) + memInfo.totalSwap = value; + else if(std::strcmp(name, "SwapFree:") == 0) + memInfo.freeSwap = value; + } + + delete [] name; if(memInfo.totalMem && memInfo.freeMem && memInfo.totalSwap && memInfo.freeSwap) break; |