protocol/ArgParser: move strtof()/strtod() switch to util/NumberParser.hxx
This commit is contained in:
@@ -21,6 +21,7 @@
|
|||||||
#include "ArgParser.hxx"
|
#include "ArgParser.hxx"
|
||||||
#include "Ack.hxx"
|
#include "Ack.hxx"
|
||||||
#include "Chrono.hxx"
|
#include "Chrono.hxx"
|
||||||
|
#include "util/NumberParser.hxx"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@@ -151,12 +152,7 @@ float
|
|||||||
ParseCommandArgFloat(const char *s)
|
ParseCommandArgFloat(const char *s)
|
||||||
{
|
{
|
||||||
char *endptr;
|
char *endptr;
|
||||||
#ifdef ANDROID
|
auto value = ParseFloat(s, &endptr);
|
||||||
/* strtof() requires API level 21 */
|
|
||||||
auto value = strtod(s, &endptr);
|
|
||||||
#else
|
|
||||||
auto value = strtof(s, &endptr);
|
|
||||||
#endif
|
|
||||||
if (endptr == s || *endptr != 0)
|
if (endptr == s || *endptr != 0)
|
||||||
throw FormatProtocolError(ACK_ERROR_ARG,
|
throw FormatProtocolError(ACK_ERROR_ARG,
|
||||||
"Float expected: %s", s);
|
"Float expected: %s", s);
|
||||||
|
@@ -78,7 +78,12 @@ ParseDouble(const char *p, char **endptr=nullptr)
|
|||||||
static inline float
|
static inline float
|
||||||
ParseFloat(const char *p, char **endptr=nullptr)
|
ParseFloat(const char *p, char **endptr=nullptr)
|
||||||
{
|
{
|
||||||
|
#if defined(__BIONIC__) && __ANDROID_API__ < 21
|
||||||
|
/* strtof() requires API level 21 */
|
||||||
return (float)ParseDouble(p, endptr);
|
return (float)ParseDouble(p, endptr);
|
||||||
|
#else
|
||||||
|
return strtof(p, endptr);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user