msvcrt: Call MSVCRT_strtoi64_l in strtoul implementation.

This commit is contained in:
Piotr Caban 2013-09-25 14:41:52 +02:00 committed by Alexandre Julliard
parent c3c44544ff
commit a449b2d57b
2 changed files with 38 additions and 29 deletions

View File

@ -726,35 +726,6 @@ int CDECL __STRINGTOLD( MSVCRT__LDOUBLE *value, char **endptr, const char *str,
return 0;
}
/******************************************************************
* strtoul (MSVCRT.@)
*/
MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
{
/* wrapper to forward libc error code to msvcrt's error codes */
unsigned long ret;
errno = 0;
ret = strtoul(nptr, end, base);
switch (errno)
{
case ERANGE: *MSVCRT__errno() = MSVCRT_ERANGE; break;
case EINVAL: *MSVCRT__errno() = MSVCRT_EINVAL; break;
default:
/* cope with the fact that we may use 64bit long integers on libc
* while msvcrt always uses 32bit long integers
*/
if (ret > MSVCRT_ULONG_MAX)
{
ret = MSVCRT_ULONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
break;
}
return ret;
}
/*********************************************************************
* strlen (MSVCRT.@)
*/
@ -918,6 +889,24 @@ MSVCRT_long CDECL MSVCRT_strtol(const char* nptr, char** end, int base)
return ret;
}
/******************************************************************
* strtoul (MSVCRT.@)
*/
MSVCRT_ulong CDECL MSVCRT_strtoul(const char* nptr, char** end, int base)
{
__int64 ret = MSVCRT_strtoi64_l(nptr, end, base, NULL);
if(ret > MSVCRT_ULONG_MAX) {
ret = MSVCRT_ULONG_MAX;
*MSVCRT__errno() = MSVCRT_ERANGE;
}else if(ret < -(__int64)MSVCRT_ULONG_MAX) {
ret = 1;
*MSVCRT__errno() = MSVCRT_ERANGE;
}
return ret;
}
/*********************************************************************
* _strtoui64_l (MSVCRT.@)
*

View File

@ -1341,6 +1341,26 @@ static void test_strtol(void)
ul = strtoul("9223372036854775807L", &e, 0);
ok(ul==4294967295ul, "wrong value %u\n", ul);
ok(errno == ERANGE, "wrong errno %d\n", errno);
errno = 0;
ul = strtoul("-2", NULL, 0);
ok(ul == -2, "wrong value %u\n", ul);
ok(errno == 0, "wrong errno %d\n", errno);
errno = 0;
ul = strtoul("-4294967294", NULL, 0);
ok(ul == 2, "wrong value %u\n", ul);
ok(errno == 0, "wrong errno %d\n", errno);
errno = 0;
ul = strtoul("-4294967295", NULL, 0);
ok(ul==1, "wrong value %u\n", ul);
ok(errno == 0, "wrong errno %d\n", errno);
errno = 0;
ul = strtoul("-4294967296", NULL, 0);
ok(ul == 1, "wrong value %u\n", ul);
ok(errno == ERANGE, "wrong errno %d\n", errno);
}
static void test_strnlen(void)