summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-02 00:38:45 +0000
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>2007-01-02 00:38:45 +0000
commit3311f35e780e465663ccda08902e759aec571dbc (patch)
tree7f06f16d296afe9a658ac7335871fad9ef635f3e /src
parentfd8932217922ea291f4102dffbfd66de4d5e9827 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp36
1 files changed, 36 insertions, 0 deletions
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;
}