2007-03-14 20:24:57 +00:00
|
|
|
#include <precomp.h>
|
|
|
|
|
2007-11-08 21:06:20 +00:00
|
|
|
unsigned long long
|
2007-03-14 20:24:57 +00:00
|
|
|
strtoull(const char *nptr, char **endptr, int base)
|
2006-11-08 11:47:44 +00:00
|
|
|
{
|
|
|
|
const char *s = nptr;
|
2007-11-08 21:06:20 +00:00
|
|
|
unsigned long long acc;
|
2006-11-08 11:47:44 +00:00
|
|
|
int c;
|
2007-11-08 21:06:20 +00:00
|
|
|
unsigned long long cutoff;
|
2006-11-08 11:47:44 +00:00
|
|
|
int neg = 0, any, cutlim;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See strtol for comments as to the logic used.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
c = *s++;
|
|
|
|
} while (isspace(c));
|
|
|
|
if (c == '-')
|
|
|
|
{
|
|
|
|
neg = 1;
|
|
|
|
c = *s++;
|
|
|
|
}
|
|
|
|
else if (c == '+')
|
|
|
|
c = *s++;
|
|
|
|
if ((base == 0 || base == 16) &&
|
|
|
|
c == '0' && (*s == 'x' || *s == 'X'))
|
|
|
|
{
|
|
|
|
c = s[1];
|
|
|
|
s += 2;
|
|
|
|
base = 16;
|
|
|
|
}
|
|
|
|
if (base == 0)
|
|
|
|
base = c == '0' ? 8 : 10;
|
2007-11-08 21:06:20 +00:00
|
|
|
cutoff = (unsigned long long)ULLONG_MAX / (unsigned long long)base;
|
|
|
|
cutlim = (unsigned long long)ULLONG_MAX % (unsigned long long)base;
|
2006-11-08 11:47:44 +00:00
|
|
|
for (acc = 0, any = 0;; c = *s++)
|
|
|
|
{
|
|
|
|
if (isdigit(c))
|
|
|
|
c -= '0';
|
|
|
|
else if (isalpha(c))
|
|
|
|
c -= isupper(c) ? 'A' - 10 : 'a' - 10;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
if (c >= base)
|
|
|
|
break;
|
|
|
|
if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
|
|
|
|
any = -1;
|
|
|
|
else {
|
|
|
|
any = 1;
|
|
|
|
acc *= base;
|
|
|
|
acc += c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (any < 0)
|
|
|
|
{
|
2007-11-08 21:06:20 +00:00
|
|
|
acc = ULLONG_MAX;
|
2011-01-04 17:52:34 +00:00
|
|
|
#ifndef _LIBCNT_
|
[CRT]
- Update file.c to recent wine. (now with locking!)
- implement/enable __wcserror, __wcserror_s, _access_s, _ctime32_s, _ctime64_s,
_cwprintf, _fseeki64, _ftelli64, _get_osplatform, _get_output_format,
_get_pgmptr, _get_wpgmptr, _get_terminate, _get_tzname, _get_unexpected,
_gmtime64_s, _i64toa_s, _i64tow_s, _initterm_e, _itoa_s, _itow_s,
_localtime32_s, _localtime64_s, _ltoa_s, _ltow_s, _putwch, _searchenv_s,
_sopen_s, _ui64toa_s, _ui64tow_s, _vcwprintf, _vsprintf_p, _waccess_s,
_wcserror, _wcserror_s, _wfopen_s, _wsopen_s, fopen_s, fprintf_s, fwprintf_s,
printf_s, strerror_s, strncpy_s, strtok_s, vfprintf_s, vfwprintf_s, vprintf_s,
vwprintf_s, wcscat_s, wcsncat_s, wcstok_s, wprintf_s. Most code comes from
wine.
- Fix __set_errno -> _set_errno and export it.
- Remove unneeded files.
[CRT_HEADERS]
- add threadmbcinfo struct.
- update some sec_api headers from mingw64 due to missing or incorrect
functions.
Patch by Samuel Serapion.
Changes to msvcrt spec by me due to winebuild.
CRLF/LF fixes.
svn path=/trunk/; revision=54651
2011-12-14 22:09:24 +00:00
|
|
|
_set_errno(ERANGE);
|
2011-01-04 17:52:34 +00:00
|
|
|
#endif
|
2006-11-08 11:47:44 +00:00
|
|
|
}
|
|
|
|
else if (neg)
|
2011-09-15 17:11:53 +00:00
|
|
|
acc = 0-acc;
|
2006-11-08 11:47:44 +00:00
|
|
|
if (endptr != 0)
|
2007-11-08 21:06:20 +00:00
|
|
|
*endptr = any ? (char *)((size_t)(s - 1)) : (char *)((size_t)nptr);
|
2006-11-08 11:47:44 +00:00
|
|
|
return acc;
|
|
|
|
}
|