From 453317b28cf8286a6bb849ab425fcce74d4148f3 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 24 Jan 2011 18:22:32 -0500 Subject: [PATCH] Fall back to sscanf if we have no other way to implement strtoll --- evutil.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/evutil.c b/evutil.c index 1d2c0fc9..227cc5b4 100644 --- a/evutil.c +++ b/evutil.c @@ -351,6 +351,8 @@ evutil_strtoll(const char *s, char **endptr, int base) r = (ev_int64_t) _atoi64(s); while (isspace(*s)) ++s; + if (*s == '-') + ++s; while (isdigit(*s)) ++s; if (endptr) @@ -358,6 +360,36 @@ evutil_strtoll(const char *s, char **endptr, int base) return r; #elif defined(WIN32) return (ev_int64_t) _strtoi64(s, endptr, base); +#elif defined(_EVENT_SIZEOF_LONG_LONG) && _EVENT_SIZEOF_LONG_LONG == 8 + long long r; + int n; + if (base != 10 && base != 16) + return 0; + if (base == 10) { + n = sscanf(s, "%lld", &r); + } else { + unsigned long long ru=0; + n = sscanf(s, "%llx", &ru); + if (ru > EV_INT64_MAX) + return 0; + r = (long long) ru; + } + if (n != 1) + return 0; + while (EVUTIL_ISSPACE(*s)) + ++s; + if (*s == '-') + ++s; + if (base == 10) { + while (EVUTIL_ISDIGIT(*s)) + ++s; + } else { + while (EVUTIL_ISXDIGIT(*s)) + ++s; + } + if (endptr) + *endptr = (char*) s; + return r; #else #error "I don't know how to parse 64-bit integers." #endif -- 2.40.0