From 3311f35e780e465663ccda08902e759aec571dbc Mon Sep 17 00:00:00 2001 From: brain Date: Tue, 2 Jan 2007 00:38:45 +0000 Subject: Add support for suffixes K, M, G (kilo, mega, gigabyte) and prefix 0x (hex) git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6209 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/configreader.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src') diff --git a/src/configreader.cpp b/src/configreader.cpp index c66b6730a..d30786438 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -1348,6 +1348,42 @@ bool ServerConfig::ConfValueInteger(ConfigDataHash &target, const std::string &t stream.str(value); if(!(stream >> result)) return false; + else + { + if (!value.empty()) + { + if (value.substr(0,2) == "0x") + { + char* endptr; + + value.erase(0,2); + result = strtol(value.c_str(), &endptr, 16); + + /* No digits found */ + if (endptr == value.c_str()) + return false; + } + else + { + char denominator = *(value.end() - 1); + switch (toupper(denominator)) + { + case 'K': + /* Kilobytes -> bytes */ + result = result * 1024; + break; + case 'M': + /* Megabytes -> bytes */ + result = result * 1024 * 1024; + break; + case 'G': + /* Gigabytes -> bytes */ + result = result * 1024 * 1024 * 1024; + break; + } + } + } + } return r; } -- cgit v1.2.3