From 7659ae1cb06c2aaa7ea491ef7a63740b0ef4abcf Mon Sep 17 00:00:00 2001 From: Dustin Sallings Date: Sat, 14 Mar 2009 23:57:38 -0700 Subject: Reformatted util.c --- util.c | 57 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/util.c b/util.c index ed2ec51..4de8199 100644 --- a/util.c +++ b/util.c @@ -8,38 +8,39 @@ #include "memcached.h" bool safe_strtoull(const char *str, unsigned long long *out) { - assert(out != NULL); - errno = 0; - *out = 0; - char *endptr; - unsigned long long ull = strtoull(str, &endptr, 10); - if (errno == ERANGE) - return false; - if (isspace(*endptr) || (*endptr == '\0' && endptr != str)) { - if ((long long) ull < 0) { - /* only check for negative signs in the uncommon case when the unsigned - * number is so big that it's negative as a signed number. */ - if (strchr(str, '-') != NULL) { + assert(out != NULL); + errno = 0; + *out = 0; + char *endptr; + unsigned long long ull = strtoull(str, &endptr, 10); + if (errno == ERANGE) return false; - } + if (isspace(*endptr) || (*endptr == '\0' && endptr != str)) { + if ((long long) ull < 0) { + /* only check for negative signs in the uncommon case when + * the unsigned number is so big that it's negative as a + * signed number. */ + if (strchr(str, '-') != NULL) { + return false; + } + } + *out = ull; + return true; } - *out = ull; - return true; - } - return false; + return false; } bool safe_strtoll(const char *str, long long *out) { - assert(out != NULL); - errno = 0; - *out = 0; - char *endptr; - long long ll = strtoll(str, &endptr, 10); - if (errno == ERANGE) + assert(out != NULL); + errno = 0; + *out = 0; + char *endptr; + long long ll = strtoll(str, &endptr, 10); + if (errno == ERANGE) + return false; + if (isspace(*endptr) || (*endptr == '\0' && endptr != str)) { + *out = ll; + return true; + } return false; - if (isspace(*endptr) || (*endptr == '\0' && endptr != str)) { - *out = ll; - return true; - } - return false; } -- cgit v1.2.1