diff options
author | Daniel Stenberg <daniel@haxx.se> | 2004-01-22 14:37:06 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2004-01-22 14:37:06 +0000 |
commit | 3efb90dd755af19eda4b4004e3fadbd3a9c6b1e7 (patch) | |
tree | 3d61f0b6152ad38779774d3a7bc685c4a21a2f4e /lib/strtoofft.c | |
parent | e4c565303580f14b977f8a25ffe5c3faa4212504 (diff) | |
download | curl-3efb90dd755af19eda4b4004e3fadbd3a9c6b1e7.tar.gz |
re-intended the code curl-style
Diffstat (limited to 'lib/strtoofft.c')
-rw-r--r-- | lib/strtoofft.c | 56 |
1 files changed, 30 insertions, 26 deletions
diff --git a/lib/strtoofft.c b/lib/strtoofft.c index 322a753e3..a6f1f01f3 100644 --- a/lib/strtoofft.c +++ b/lib/strtoofft.c @@ -55,9 +55,11 @@ Curl_strtoll(const char *nptr, char **endptr, int base) if (end[0] == '-') { is_negative = 1; end++; - } else if (end[0] == '+') { + } + else if (end[0] == '+') { end++; - } else if (end[0] == '\0') { + } + else if (end[0] == '\0') { /* We had nothing but perhaps some whitespace -- there was no number. */ if (endptr) { *endptr = end; @@ -71,7 +73,8 @@ Curl_strtoll(const char *nptr, char **endptr, int base) end += 2; base = 16; } - } else if (end[0] == '0') { + } + else if (end[0] == '0') { if (base == 8 || base == 0) { end++; base = 8; @@ -90,16 +93,15 @@ Curl_strtoll(const char *nptr, char **endptr, int base) overflow = 0; for (i = get_char(end[0], base); i != -1; - end++, i = get_char(end[0], base)) - { + end++, i = get_char(end[0], base)) { newval = base * value + i; if (newval < value) { /* We've overflowed. */ overflow = 1; break; - } else { - value = newval; } + else + value = newval; } if (!overflow) { @@ -107,19 +109,18 @@ Curl_strtoll(const char *nptr, char **endptr, int base) /* Fix the sign. */ value *= -1; } - } else { - if (is_negative) { + } + else { + if (is_negative) value = 0x8000000000000000L; - } else { + else value = 0x7FFFFFFFFFFFFFFFL; - } errno = ERANGE; } - if (endptr) { + if (endptr) *endptr = end; - } return value; } @@ -134,20 +135,23 @@ Curl_strtoll(const char *nptr, char **endptr, int base) * * @return the value of c in base, or -1 if c isn't in range */ -static int get_char(char c, int base) { - int value = -1; - if (c <= '9' && c >= '0') { - value = c - '0'; - } else if (c <= 'Z' && c >= 'A') { - value = c - 'A' + 10; - } else if (c <= 'z' && c >= 'a') { - value = c - 'a' + 10; - } +static int get_char(char c, int base) +{ + int value = -1; + if (c <= '9' && c >= '0') { + value = c - '0'; + } + else if (c <= 'Z' && c >= 'A') { + value = c - 'A' + 10; + } + else if (c <= 'z' && c >= 'a') { + value = c - 'a' + 10; + } - if (value >= base) { - value = -1; - } + if (value >= base) { + value = -1; + } - return value; + return value; } #endif /* Only present if we need strtoll, but don't have it. */ |