3 * Copyright (C) 2005 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 * PROJECT: ReactOS kernel
22 * FILE: ntoskrnl/dbg/kdb_string.c
23 * PURPOSE: Kernel debugger string functions
24 * PROGRAMMER: Gregor Anich (blight@blight.eu.org)
29 /* INCLUDES ******************************************************************/
33 /* FUNCTIONS *****************************************************************/
58 * Convert a string to an unsigned long integer.
60 * Ignores `locale' stuff. Assumes that the upper and lower case
61 * alphabets and digits are each contiguous.
64 strtoul(const char *nptr
, char **endptr
, int base
)
70 int neg
= 0, any
, cutlim
;
73 * See strtol for comments as to the logic used.
85 if ((base
== 0 || base
== 16) &&
86 c
== '0' && (*s
== 'x' || *s
== 'X'))
93 base
= c
== '0' ? 8 : 10;
94 cutoff
= (unsigned long)0xffffffff / (unsigned long)base
;
95 cutlim
= (unsigned long)0xffffffff % (unsigned long)base
;
96 for (acc
= 0, any
= 0;; c
= *s
++)
101 c
-= isupper(c
) ? 'A' - 10 : 'a' - 10;
106 if (any
< 0 || acc
> cutoff
|| (acc
== cutoff
&& c
> cutlim
))
121 *endptr
= any
? (char *)((size_t)(s
- 1)) : (char *)((size_t)nptr
);