ReactOS
0.4.16-dev-835-gd769f56
strtoull.c
Go to the documentation of this file.
1
#include <precomp.h>
2
3
unsigned
long
long
4
CDECL
5
strtoull
(
const
char
*nptr,
char
**endptr,
int
base
)
6
{
7
const
char
*
s
= nptr;
8
unsigned
long
long
acc;
9
int
c
;
10
unsigned
long
long
cutoff;
11
int
neg = 0, any, cutlim;
12
13
/*
14
* See strtol for comments as to the logic used.
15
*/
16
do
{
17
c
= *
s
++;
18
}
while
(
isspace
(
c
));
19
if
(
c
==
'-'
)
20
{
21
neg = 1;
22
c
= *
s
++;
23
}
24
else
if
(
c
==
'+'
)
25
c
= *
s
++;
26
if
((
base
== 0 ||
base
== 16) &&
27
c
==
'0'
&& (*
s
==
'x'
|| *
s
==
'X'
))
28
{
29
c
=
s
[1];
30
s
+= 2;
31
base
= 16;
32
}
33
if
(
base
== 0)
34
base
=
c
==
'0'
? 8 : 10;
35
cutoff = (
unsigned
long
long
)
ULLONG_MAX
/ (
unsigned
long
long
)
base
;
36
cutlim = (
unsigned
long
long
)
ULLONG_MAX
% (
unsigned
long
long
)
base
;
37
for
(acc = 0, any = 0;;
c
= *
s
++)
38
{
39
if
(
isdigit
(
c
))
40
c
-=
'0'
;
41
else
if
(
isalpha
(
c
))
42
c
-=
isupper
(
c
) ?
'A'
- 10 :
'a'
- 10;
43
else
44
break
;
45
if
(
c
>=
base
)
46
break
;
47
if
(any < 0 || acc > cutoff || (acc == cutoff &&
c
> cutlim))
48
any = -1;
49
else
{
50
any = 1;
51
acc *=
base
;
52
acc +=
c
;
53
}
54
}
55
if
(any < 0)
56
{
57
acc =
ULLONG_MAX
;
58
#ifndef _LIBCNT_
59
_set_errno
(
ERANGE
);
60
#endif
61
}
62
else
if
(neg)
63
acc = 0-acc;
64
if
(endptr != 0)
65
*endptr = any ? (
char
*)((
size_t
)(
s
- 1)) : (
char
*)((
size_t
)nptr);
66
return
acc;
67
}
isspace
#define isspace(c)
Definition:
acclib.h:69
isalpha
#define isalpha(c)
Definition:
acclib.h:74
isdigit
#define isdigit(c)
Definition:
acclib.h:68
ERANGE
#define ERANGE
Definition:
acclib.h:92
isupper
#define isupper(c)
Definition:
acclib.h:71
CDECL
#define CDECL
Definition:
compat.h:29
s
GLdouble s
Definition:
gl.h:2039
c
const GLubyte * c
Definition:
glext.h:8905
ULLONG_MAX
#define ULLONG_MAX
Definition:
limits.h:47
c
#define c
Definition:
ke_i.h:80
long
#define long
Definition:
qsort.c:33
_set_errno
errno_t __cdecl _set_errno(_In_ int _Value)
strtoull
#define strtoull
Definition:
stabs.c:58
base
Definition:
uninitialized_test.cpp:81
sdk
lib
crt
string
strtoull.c
Generated on Thu Mar 20 2025 06:14:08 for ReactOS by
1.9.6