ReactOS
0.4.16-dev-91-g764881a
strtoi64.c
Go to the documentation of this file.
1
#include <precomp.h>
2
3
/* Based on Wine Staging 1.9.9 - dlls/msvcrt/string.c */
4
5
/*********************************************************************
6
* _strtoi64_l (MSVCRT.@)
7
*
8
* FIXME: locale parameter is ignored
9
*/
10
__int64
CDECL
_strtoi64_l
(
const
char
*nptr,
char
**endptr,
int
base
,
_locale_t
locale
)
11
{
12
const
char
*
p
= nptr;
13
BOOL
negative =
FALSE
;
14
BOOL
got_digit =
FALSE
;
15
__int64
ret
= 0;
16
17
#ifndef _LIBCNT_
18
TRACE
(
"(%s %p %d %p)\n"
,
debugstr_a
(nptr), endptr,
base
,
locale
);
19
#endif
20
21
#ifndef __REACTOS__
22
if
(!
MSVCRT_CHECK_PMT
(nptr !=
NULL
))
return
0;
23
#endif
24
if
(!
MSVCRT_CHECK_PMT
(
base
== 0 ||
base
>= 2))
return
0;
25
if
(!
MSVCRT_CHECK_PMT
(
base
<= 36))
return
0;
26
27
while
(
isspace
(*nptr)) nptr++;
28
29
if
(*nptr ==
'-'
) {
30
negative =
TRUE
;
31
nptr++;
32
}
else
if
(*nptr ==
'+'
)
33
nptr++;
34
35
if
((
base
==0 ||
base
==16) && *nptr==
'0'
&&
tolower
(*(nptr+1))==
'x'
) {
36
base
= 16;
37
nptr += 2;
38
}
39
40
if
(
base
== 0) {
41
if
(*nptr==
'0'
)
42
base
= 8;
43
else
44
base
= 10;
45
}
46
47
while
(*nptr) {
48
char
cur
=
tolower
(*nptr);
49
int
v
;
50
51
if
(
isdigit
(
cur
)) {
52
if
(
cur
>=
'0'
+
base
)
53
break
;
54
v
=
cur
-
'0'
;
55
}
else
{
56
if
(
cur
<
'a'
||
cur
>=
'a'
+
base
-10)
57
break
;
58
v
=
cur
-
'a'
+10;
59
}
60
got_digit =
TRUE
;
61
62
if
(negative)
63
v
= -
v
;
64
65
nptr++;
66
67
if
(!negative && (
ret
>
_I64_MAX
/
base
||
ret
*
base
>
_I64_MAX
-
v
)) {
68
ret
=
_I64_MAX
;
69
#ifndef _LIBCNT_
70
*
_errno
() =
ERANGE
;
71
#endif
72
}
73
else
if
(negative && (
ret
<
_I64_MIN
/
base
||
ret
*
base
<
_I64_MIN
-
v
)) {
74
ret
=
_I64_MIN
;
75
#ifndef _LIBCNT_
76
*
_errno
() =
ERANGE
;
77
#endif
78
}
79
else
80
ret
=
ret
*
base
+
v
;
81
}
82
83
if
(endptr)
84
*endptr = (
char
*)(got_digit ? nptr :
p
);
85
86
return
ret
;
87
}
88
89
__int64
90
_strtoi64
(
const
char
*nptr,
char
**endptr,
int
base
)
91
{
92
return
_strtoi64_l
(nptr, endptr,
base
,
NULL
);
93
}
94
95
96
/* EOF */
isspace
#define isspace(c)
Definition:
acclib.h:69
isdigit
#define isdigit(c)
Definition:
acclib.h:68
ERANGE
#define ERANGE
Definition:
acclib.h:92
tolower
int tolower(int c)
Definition:
utclib.c:902
__int64
#define __int64
Definition:
basetyps.h:16
locale
Definition:
_locale.h:75
NULL
#define NULL
Definition:
types.h:112
TRUE
#define TRUE
Definition:
types.h:120
FALSE
#define FALSE
Definition:
types.h:117
CDECL
#define CDECL
Definition:
compat.h:29
BOOL
unsigned int BOOL
Definition:
ntddk_ex.h:94
cur
FxCollectionEntry * cur
Definition:
fxresourceapi.cpp:412
v
const GLdouble * v
Definition:
gl.h:2040
p
GLfloat GLfloat p
Definition:
glext.h:8902
_I64_MAX
#define _I64_MAX
Definition:
limits.h:62
_I64_MIN
#define _I64_MIN
Definition:
limits.h:61
debugstr_a
#define debugstr_a
Definition:
kernel32.h:31
MSVCRT_CHECK_PMT
#define MSVCRT_CHECK_PMT(x)
Definition:
mbstowcs_s.c:26
_errno
_CRTIMP int *__cdecl _errno(void)
Definition:
errno.c:17
TRACE
#define TRACE(s)
Definition:
solgame.cpp:4
_strtoi64
__int64 _strtoi64(const char *nptr, char **endptr, int base)
Definition:
strtoi64.c:90
_strtoi64_l
__int64 CDECL _strtoi64_l(const char *nptr, char **endptr, int base, _locale_t locale)
Definition:
strtoi64.c:10
base
Definition:
uninitialized_test.cpp:81
localeinfo_struct
Definition:
crtdefs.h:442
ret
int ret
Definition:
wcstombs-tests.c:31
sdk
lib
crt
string
strtoi64.c
Generated on Sun Oct 6 2024 06:13:04 for ReactOS by
1.9.6