From 84f69d7aacef531c0ad809d7511c7ab7bce7469c Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 20 Sep 2008 18:06:42 +0200 Subject: /proc/meminfo ohne regul?re Ausdr?cke verarbeiten --- src/Common/Backends/Makefile.in | 2 -- src/Common/Backends/SystemBackendProc.cpp | 29 ++++++++++++++--------------- 2 files changed, 14 insertions(+), 17 deletions(-) (limited to 'src/Common/Backends') 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 #include +#include 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; -- cgit v1.2.3