From 0f8d223c7fcc7e61808716dbb740786b9d95a991 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 9 Feb 2018 20:27:00 +0100 Subject: [PATCH] protocol/ArgParser: move strtof()/strtod() switch to util/NumberParser.hxx --- src/protocol/ArgParser.cxx | 8 ++------ src/util/NumberParser.hxx | 5 +++++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/protocol/ArgParser.cxx b/src/protocol/ArgParser.cxx index 2665270e6..47fdfa405 100644 --- a/src/protocol/ArgParser.cxx +++ b/src/protocol/ArgParser.cxx @@ -21,6 +21,7 @@ #include "ArgParser.hxx" #include "Ack.hxx" #include "Chrono.hxx" +#include "util/NumberParser.hxx" #include @@ -151,12 +152,7 @@ float ParseCommandArgFloat(const char *s) { char *endptr; -#ifdef ANDROID - /* strtof() requires API level 21 */ - auto value = strtod(s, &endptr); -#else - auto value = strtof(s, &endptr); -#endif + auto value = ParseFloat(s, &endptr); if (endptr == s || *endptr != 0) throw FormatProtocolError(ACK_ERROR_ARG, "Float expected: %s", s); diff --git a/src/util/NumberParser.hxx b/src/util/NumberParser.hxx index 47e9aacbd..67d42affa 100644 --- a/src/util/NumberParser.hxx +++ b/src/util/NumberParser.hxx @@ -78,7 +78,12 @@ ParseDouble(const char *p, char **endptr=nullptr) static inline float ParseFloat(const char *p, char **endptr=nullptr) { +#if defined(__BIONIC__) && __ANDROID_API__ < 21 + /* strtof() requires API level 21 */ return (float)ParseDouble(p, endptr); +#else + return strtof(p, endptr); +#endif } #endif