Fix strtoull implementation and add it to build files. Based on patch by Mark Junker <mjscod@gmx.de>.

svn path=/trunk/; revision=17797
This commit is contained in:
Filip Navara 2005-09-11 12:36:09 +00:00
parent a43952c66b
commit c25a8a58af
2 changed files with 9 additions and 7 deletions

View file

@ -317,6 +317,7 @@
<file>senv.c</file>
<file>strtod.c</file>
<file>strtoul.c</file>
<file>strtoull.c</file>
<file>swab.c</file>
<file>wcstod.c</file>
<file>wcstombs.c</file>

View file

@ -4,7 +4,8 @@
#include <ctype.h>
#include <errno.h>
#include <stdlib.h>
//#include <msvcrt/unconst.h>
#include <stdint.h>
#include <internal/file.h>
/*
* Convert a string to an unsigned long integer.
@ -12,13 +13,13 @@
* Ignores `locale' stuff. Assumes that the upper and lower case
* alphabets and digits are each contiguous.
*/
unsigned long
uint64_t
strtoull(const char *nptr, char **endptr, int base)
{
const char *s = nptr;
unsigned long acc;
uint64_t acc;
int c;
unsigned long cutoff;
uint64_t cutoff;
int neg = 0, any, cutlim;
/*
@ -43,8 +44,8 @@ strtoull(const char *nptr, char **endptr, int base)
}
if (base == 0)
base = c == '0' ? 8 : 10;
cutoff = (unsigned long)ULONG_MAX / base;
cutlim = (unsigned long)ULONG_MAX % base;
cutoff = UINT64_MAX / base;
cutlim = (int)(UINT64_MAX % base);
for (acc = 0, any = 0;; c = *s++)
{
if (isdigit(c))
@ -65,7 +66,7 @@ strtoull(const char *nptr, char **endptr, int base)
}
if (any < 0)
{
acc = ULONG_MAX;
acc = UINT64_MAX;
__set_errno ( ERANGE );
}
else if (neg)