ReactOS 0.4.16-dev-979-g79f281e
xtoa.cpp File Reference
#include <corecrt_internal.h>
#include <corecrt_internal_securecrt.h>
#include <limits.h>
#include <stdlib.h>
Include dependency graph for xtoa.cpp:

Go to the source code of this file.

Classes

struct  anonymous_namespace{xtoa.cpp}::make_signed< unsigned long >
 
struct  anonymous_namespace{xtoa.cpp}::make_signed< unsigned __int64 >
 

Namespaces

namespace  anonymous_namespace{xtoa.cpp}
 

Functions

template<typename UnsignedInteger , typename Character >
 _Success_ (return==0) static errno_t __cdecl common_xtox(UnsignedInteger const original_value
 
 _Out_writes_z_ (buffer_count) Character *const buffer
 
 _When_ (is_negative==true, _In_range_(>=, 2)) _In_range_(>
 
size_t const unsigned const bool const is_negative throw ()
 
errno_t __cdecl _itoa_s (int const value, char *const buffer, size_t const buffer_count, int const radix)
 
errno_t __cdecl _ltoa_s (long const value, char *const buffer, size_t const buffer_count, int const radix)
 
errno_t __cdecl _ultoa_s (unsigned long const value, char *const buffer, size_t const buffer_count, int const radix)
 
char *__cdecl _itoa (int const value, char *const buffer, int const radix)
 
char *__cdecl _ltoa (long const value, char *const buffer, int const radix)
 
char *__cdecl _ultoa (unsigned long const value, char *const buffer, int const radix)
 
errno_t __cdecl _i64toa_s (__int64 const value, char *const buffer, size_t const buffer_count, int const radix)
 
errno_t __cdecl _ui64toa_s (unsigned __int64 const value, char *const buffer, size_t const buffer_count, int const radix)
 
char *__cdecl _i64toa (__int64 const value, char *const buffer, int const radix)
 
char *__cdecl _ui64toa (unsigned __int64 const value, char *const buffer, int const radix)
 
errno_t __cdecl _itow_s (int const value, wchar_t *const buffer, size_t const buffer_count, int const radix)
 
errno_t __cdecl _ltow_s (long const value, wchar_t *const buffer, size_t const buffer_count, int const radix)
 
errno_t __cdecl _ultow_s (unsigned long const value, wchar_t *const buffer, size_t const buffer_count, int const radix)
 
wchar_t *__cdecl _itow (int const value, wchar_t *const buffer, int const radix)
 
wchar_t *__cdecl _ltow (long const value, wchar_t *const buffer, int const radix)
 
wchar_t *__cdecl _ultow (unsigned long const value, wchar_t *const buffer, int const radix)
 
errno_t __cdecl _i64tow_s (__int64 const value, wchar_t *const buffer, size_t const buffer_count, int const radix)
 
errno_t __cdecl _ui64tow_s (unsigned __int64 const value, wchar_t *const buffer, size_t const buffer_count, int const radix)
 
wchar_t *__cdecl _i64tow (__int64 const value, wchar_t *const buffer, int const radix)
 
wchar_t *__cdecl _ui64tow (unsigned __int64 const value, wchar_t *const buffer, int const radix)
 

Variables

size_t const buffer_count
 
size_t const unsigned const radix
 

Function Documentation

◆ _i64toa()

char *__cdecl _i64toa ( __int64 const  value,
char *const  buffer,
int const  radix 
)

Definition at line 226 of file xtoa.cpp.

231{
232 bool const is_negative = radix == 10 && value < 0;
233 common_xtox(static_cast<unsigned __int64>(value), buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, is_negative);
234 return buffer;
235}
#define __int64
Definition: basetyps.h:16
#define _CRT_UNBOUNDED_BUFFER_SIZE
GLuint buffer
Definition: glext.h:5915
Definition: pdh_main.c:96
size_t const unsigned const radix
Definition: xtoa.cpp:37

◆ _i64toa_s()

errno_t __cdecl _i64toa_s ( __int64 const  value,
char *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 203 of file xtoa.cpp.

209{
210 bool const is_negative = radix == 10 && value < 0;
211 return common_xtox_s(static_cast<unsigned __int64>(value), buffer, buffer_count, radix, is_negative);
212}
size_t const buffer_count
Definition: xtoa.cpp:36

◆ _i64tow()

wchar_t *__cdecl _i64tow ( __int64 const  value,
wchar_t *const  buffer,
int const  radix 
)

Definition at line 350 of file xtoa.cpp.

355{
356 bool const is_negative = radix == 10 && value < 0;
357 common_xtox(static_cast<unsigned __int64>(value), buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, is_negative);
358 return buffer;
359}

◆ _i64tow_s()

errno_t __cdecl _i64tow_s ( __int64 const  value,
wchar_t *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 327 of file xtoa.cpp.

333{
334 bool const is_negative = radix == 10 && value < 0;
335 return common_xtox_s(static_cast<unsigned __int64>(value), buffer, buffer_count, radix, is_negative);
336}

◆ _itoa()

char *__cdecl _itoa ( int const  value,
char *const  buffer,
int const  radix 
)

Definition at line 164 of file xtoa.cpp.

169{
170 bool const is_negative = radix == 10 && value < 0;
171 common_xtox(static_cast<unsigned long>(value), buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, is_negative);
172 return buffer;
173}

◆ _itoa_s()

errno_t __cdecl _itoa_s ( int const  value,
char *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 130 of file xtoa.cpp.

136{
137 bool const is_negative = radix == 10 && value < 0;
138 return common_xtox_s(static_cast<unsigned long>(value), buffer, buffer_count, radix, is_negative);
139}

◆ _itow()

wchar_t *__cdecl _itow ( int const  value,
wchar_t *const  buffer,
int const  radix 
)

Definition at line 288 of file xtoa.cpp.

293{
294 bool const is_negative = radix == 10 && value < 0;
295 common_xtox(static_cast<unsigned long>(value), buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, is_negative);
296 return buffer;
297}

◆ _itow_s()

errno_t __cdecl _itow_s ( int const  value,
wchar_t *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 254 of file xtoa.cpp.

260{
261 bool const is_negative = radix == 10 && value < 0;
262 return common_xtox_s(static_cast<unsigned long>(value), buffer, buffer_count, radix, is_negative);
263}

◆ _ltoa()

char *__cdecl _ltoa ( long const  value,
char *const  buffer,
int const  radix 
)

Definition at line 175 of file xtoa.cpp.

180{
181 bool const is_negative = radix == 10 && value < 0;
182 common_xtox(static_cast<unsigned long>(value), buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, is_negative);
183 return buffer;
184}

◆ _ltoa_s()

errno_t __cdecl _ltoa_s ( long const  value,
char *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 141 of file xtoa.cpp.

147{
148 bool const is_negative = radix == 10 && value < 0;
149 return common_xtox_s(static_cast<unsigned long>(value), buffer, buffer_count, radix, is_negative);
150}

◆ _ltow()

wchar_t *__cdecl _ltow ( long const  value,
wchar_t *const  buffer,
int const  radix 
)

Definition at line 299 of file xtoa.cpp.

304{
305 bool const is_negative = radix == 10 && value < 0;
306 common_xtox(static_cast<unsigned long>(value), buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, is_negative);
307 return buffer;
308}

◆ _ltow_s()

errno_t __cdecl _ltow_s ( long const  value,
wchar_t *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 265 of file xtoa.cpp.

271{
272 bool const is_negative = radix == 10 && value < 0;
273 return common_xtox_s(static_cast<unsigned long>(value), buffer, buffer_count, radix, is_negative);
274}

◆ _Out_writes_z_()

_Out_writes_z_ ( buffer_count  ) const

◆ _Success_()

template<typename UnsignedInteger , typename Character >
_Success_ ( return  = = 0) const

◆ _ui64toa()

char *__cdecl _ui64toa ( unsigned __int64 const  value,
char *const  buffer,
int const  radix 
)

Definition at line 237 of file xtoa.cpp.

242{
243 common_xtox(value, buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, false);
244 return buffer;
245}

◆ _ui64toa_s()

errno_t __cdecl _ui64toa_s ( unsigned __int64 const  value,
char *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 214 of file xtoa.cpp.

220{
221 return common_xtox_s(value, buffer, buffer_count, radix, false);
222}

◆ _ui64tow()

wchar_t *__cdecl _ui64tow ( unsigned __int64 const  value,
wchar_t *const  buffer,
int const  radix 
)

Definition at line 361 of file xtoa.cpp.

366{
367 common_xtox(value, buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, false);
368 return buffer;
369}

◆ _ui64tow_s()

errno_t __cdecl _ui64tow_s ( unsigned __int64 const  value,
wchar_t *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 338 of file xtoa.cpp.

344{
345 return common_xtox_s(value, buffer, buffer_count, radix, false);
346}

◆ _ultoa()

char *__cdecl _ultoa ( unsigned long const  value,
char *const  buffer,
int const  radix 
)

Definition at line 186 of file xtoa.cpp.

191{
192 common_xtox(value, buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, false);
193 return buffer;
194}

◆ _ultoa_s()

errno_t __cdecl _ultoa_s ( unsigned long const  value,
char *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 152 of file xtoa.cpp.

158{
159 return common_xtox_s(value, buffer, buffer_count, radix, false);
160}

◆ _ultow()

wchar_t *__cdecl _ultow ( unsigned long const  value,
wchar_t *const  buffer,
int const  radix 
)

Definition at line 310 of file xtoa.cpp.

315{
316 common_xtox(value, buffer, _CRT_UNBOUNDED_BUFFER_SIZE, radix, false);
317 return buffer;
318}

◆ _ultow_s()

errno_t __cdecl _ultow_s ( unsigned long const  value,
wchar_t *const  buffer,
size_t const  buffer_count,
int const  radix 
)

Definition at line 276 of file xtoa.cpp.

282{
283 return common_xtox_s(value, buffer, buffer_count, radix, false);
284}

◆ _When_()

_When_ ( is_negative  = true,
_In_range_(>=, 2)   
)

◆ throw()

size_t const unsigned const bool const is_negative throw ( )

Definition at line 39 of file xtoa.cpp.

40{
41// OACR isn't able to track that p stays within the bounds of [buffer, buffer + buffer_count) so manually verified and disabled warning
42#pragma warning(push)
43#pragma warning(disable:26014)
44 Character* p = buffer; // pointer to traverse the string
45 size_t length = 0; // current length of string
46
47 UnsignedInteger remaining_value = original_value;;
48
49 if (is_negative)
50 {
51 *p++ = '-';
52 ++length;
53
54 remaining_value = static_cast<UnsignedInteger>(
55 -static_cast<typename make_signed<UnsignedInteger>::type>(remaining_value)
56 );
57 }
58
59 Character* first_digit = p;
60
61 do
62 {
63 unsigned const digit = static_cast<unsigned>(remaining_value % radix);
64 remaining_value /= radix;
65
66 // Convert to ASCII and store:
67 if (digit > 9)
68 {
69 *p++ = static_cast<Character>(digit - 10 + 'a');
70 }
71 else
72 {
73 *p++ = static_cast<Character>(digit + '0');
74 }
75
76 ++length;
77 }
78 while (remaining_value > 0 && length < buffer_count);
79
80 if (length >= buffer_count)
81 {
82 buffer[0] = '\0';
84 }
85
86 // We now have the digits of the number in the buffer, but in reverse order.
87 // Reverse the order, but first terminate the string:
88 *p-- = '\0';
89
90 do
91 {
92 Character const t = *p;
93 *p = *first_digit;
94 *first_digit = t;
95 --p;
96 ++first_digit;
97 }
98 while (first_digit < p);
99
100 return 0;
101#pragma warning(pop)
102}
#define ERANGE
Definition: acclib.h:92
char typename[32]
Definition: main.c:84
GLdouble GLdouble t
Definition: gl.h:2047
GLuint GLsizei GLsizei * length
Definition: glext.h:6040
GLfloat GLfloat p
Definition: glext.h:8902
#define _VALIDATE_RETURN_ERRCODE(expr, errorcode)

Variable Documentation

◆ buffer_count

◆ radix