summaryrefslogtreecommitdiff
path: root/src/Main.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@musicpd.org>2019-05-29 22:44:05 +0200
committerMax Kellermann <max@musicpd.org>2019-05-29 22:44:05 +0200
commit4eb101f0466fe2a5c21a8a0370d2cb85ce3ca995 (patch)
tree74795cf46642ffac46bed1fdb04ffec560ed372f /src/Main.cxx
parentaf7970337bd910e3f3c922007faa8d755e2e4b4c (diff)
config/Parser: add ParseSize()
Supports suffixes such as "kB" and "MB".
Diffstat (limited to 'src/Main.cxx')
-rw-r--r--src/Main.cxx7
1 files changed, 3 insertions, 4 deletions
diff --git a/src/Main.cxx b/src/Main.cxx
index 7adf42689..86a10f3d2 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -58,6 +58,7 @@
#include "config/Defaults.hxx"
#include "config/Option.hxx"
#include "config/Domain.hxx"
+#include "config/Parser.hxx"
#include "util/RuntimeError.hxx"
#include "util/ScopeExit.hxx"
@@ -280,12 +281,10 @@ initialize_decoder_and_player(Instance &instance,
param = config.GetParam(ConfigOption::AUDIO_BUFFER_SIZE);
if (param != nullptr) {
buffer_size = param->With([](const char *s){
- char *test;
- long tmp = strtol(s, &test, 10);
- if (*test != '\0' || tmp <= 0 || tmp == LONG_MAX)
+ size_t result = ParseSize(s, KILOBYTE);
+ if (result <= 0)
throw FormatRuntimeError("buffer size \"%s\" is not a "
"positive integer", s);
- size_t result = tmp * KILOBYTE;
if (result < MIN_BUFFER_SIZE) {
FormatWarning(config_domain, "buffer size %lu is too small, using %lu bytes instead",