From d018690dece24cf7f636b46556c14100f425997d Mon Sep 17 00:00:00 2001 From: Lei Zhang Date: Fri, 18 Jul 2008 17:17:16 -0700 Subject: [PATCH] [PATCH] ntdll: Use our own implementation of atoi. --- dlls/ntdll/string.c | 23 ++++++++++++++++++++++- dlls/ntdll/tests/string.c | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 1 deletions(-) diff --git a/dlls/ntdll/string.c b/dlls/ntdll/string.c index ebfa6fb..6b36364 100644 --- a/dlls/ntdll/string.c +++ b/dlls/ntdll/string.c @@ -466,10 +466,31 @@ ULONG __cdecl NTDLL_strtoul( const char *nptr, char **endptr, int base ) /********************************************************************* * atoi (NTDLL.@) + * + * Same implementation as _atoi64. */ int __cdecl NTDLL_atoi( const char *nptr ) { - return atoi( nptr ); + int RunningTotal = 0; + char bMinus = 0; + + while (*nptr == ' ' || (*nptr >= '\011' && *nptr <= '\015')) { + nptr++; + } /* while */ + + if (*nptr == '+') { + nptr++; + } else if (*nptr == '-') { + bMinus = 1; + nptr++; + } /* if */ + + while (*nptr >= '0' && *nptr <= '9') { + RunningTotal = RunningTotal * 10 + *nptr - '0'; + nptr++; + } /* while */ + + return bMinus ? -RunningTotal : RunningTotal; } diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c index e9bf5e1..08d68e4 100644 --- a/dlls/ntdll/tests/string.c +++ b/dlls/ntdll/tests/string.c @@ -893,6 +893,18 @@ static void test_wtoi(void) } /* for */ } +static void test_atoi(void) +{ + int test_num; + int result; + + for (test_num = 0; test_num < NB_STR2LONG; test_num++) { + result = patoi(str2long[test_num].str); + ok(result == str2long[test_num].value, + "(test %d): call failed: _atoi(\"%s\") has result %d, expected: %d\n", + test_num, str2long[test_num].str, result, str2long[test_num].value); + } /* for */ +} static void test_wtol(void) { @@ -1095,4 +1107,6 @@ START_TEST(string) test_wtoi64(); if (p_wcschr && p_wcsrchr) test_wcsfuncs(); + if (patoi) + test_atoi(); } -- 1.5.4.5