This is the mail archive of the
cygwin@sourceware.cygnus.com
mailing list for the Cygwin project.
Re: FW: Missing strtoull()...: long long standard
- To: root <root at jacob dot remcomp dot fr>
- Subject: Re: FW: Missing strtoull()...: long long standard
- From: Fergus Henderson <fjh at cs dot mu dot OZ dot AU>
- Date: Mon, 20 Jul 1998 14:55:11 +1000
- Cc: Brendan Simon <brendan at dgs dot monash dot edu dot au>, gnu-win32 at cygnus dot com
- References: <35AF1517.A5C180B6@dgs.monash.edu.au> <m0yxpXX-0002fdC@jacob.remcomp.fr>
On 19-Jul-1998, root <root@jacob.remcomp.fr> wrote:
> As to strtoll, my system uses atoll, what should be equivalent...
> It is not that complicated actually...
>
> Here it is:
> ----------------------------------------------------- strtoll.c-----------
> long long _strtoll(char *str)
> {
> long long result = 0;
> int negative=0;
>
> while (*str == ' ' || *str == '\t')
> str++;
> if (*str == '+')
> str++;
> else if (*str == '-') {
> negative = 1;
> str++;
> }
>
> while (*str >= '0' && *str <= '9') {
> result = (result*10)+(*str++ - '0');
> }
> return negative ? -result : result;
> }
That version is buggy; it won't handle the most negative number correctly.
I think changing the last few lines to
result = (result*10) - (*str++ - '0');
}
return negative ? result : -result;
should fix the bug.
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3 | -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".