ReactOS  0.4.15-dev-1632-g4e289ce
strtoi64.c File Reference
#include <precomp.h>
Include dependency graph for strtoi64.c:

Go to the source code of this file.

Functions

__int64 CDECL _strtoi64_l (const char *nptr, char **endptr, int base, _locale_t locale)
 
__int64 _strtoi64 (const char *nptr, char **endptr, int base)
 

Function Documentation

◆ _strtoi64()

__int64 _strtoi64 ( const char nptr,
char **  endptr,
int  base 
)

Definition at line 90 of file strtoi64.c.

91 {
92  return _strtoi64_l(nptr, endptr, base, NULL);
93 }
#define NULL
Definition: types.h:112
__int64 CDECL _strtoi64_l(const char *nptr, char **endptr, int base, _locale_t locale)
Definition: strtoi64.c:10

◆ _strtoi64_l()

__int64 CDECL _strtoi64_l ( const char nptr,
char **  endptr,
int  base,
_locale_t  locale 
)

Definition at line 10 of file strtoi64.c.

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 }
#define isspace(c)
Definition: acclib.h:69
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
Definition: _locale.h:75
unsigned int BOOL
Definition: ntddk_ex.h:94
#define isdigit(c)
Definition: acclib.h:68
#define _I64_MAX
Definition: limits.h:62
#define TRACE(s)
Definition: solgame.cpp:4
#define debugstr_a
Definition: kernel32.h:31
_CRTIMP int *__cdecl _errno(void)
Definition: errno.c:19
#define ERANGE
Definition: acclib.h:92
int ret
#define MSVCRT_CHECK_PMT(x)
Definition: mbstowcs_s.c:26
FxCollectionEntry * cur
#define _I64_MIN
Definition: limits.h:61
const GLdouble * v
Definition: gl.h:2040
#define NULL
Definition: types.h:112
GLfloat GLfloat p
Definition: glext.h:8902
int tolower(int c)
Definition: utclib.c:902
#define __int64
Definition: basetyps.h:16

Referenced by _strtoi64().