2019-01-14 14:31:49 +01:00
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
// GNU GPL OS/K //
|
|
|
|
|
// //
|
|
|
|
|
// Authors: spectral` //
|
|
|
|
|
// NeoX //
|
|
|
|
|
// //
|
|
|
|
|
// Desc: Conversion utilities - atoi family //
|
|
|
|
|
//----------------------------------------------------------------------------//
|
|
|
|
|
|
|
|
|
|
#include <kaleid.h>
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// String to integer
|
|
|
|
|
// Do not change errno
|
|
|
|
|
//
|
|
|
|
|
#define _ATOI_IMPL(_Name, _Type, _Func) \
|
|
|
|
|
_Type _Name(const char *str) { \
|
2019-01-14 23:16:26 +01:00
|
|
|
|
__get_errno(old); \
|
2019-01-14 14:31:49 +01:00
|
|
|
|
_Type ret = (_Type)_Func(str, NULL, 0); \
|
2019-01-14 23:16:26 +01:00
|
|
|
|
__set_errno(old); \
|
2019-01-14 14:31:49 +01:00
|
|
|
|
return ret; \
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ISO C does not allow extra ‘;’ outside of a function
|
|
|
|
|
#if defined(_NEED_ATOI)
|
|
|
|
|
_ATOI_IMPL(atoi, int, strtol)
|
|
|
|
|
#elif defined(_NEED_ATOL)
|
|
|
|
|
_ATOI_IMPL(atol, long, strtol)
|
|
|
|
|
#elif defined(_NEED_ATOU)
|
|
|
|
|
_ATOI_IMPL(atou, uint, strtoul)
|
|
|
|
|
#elif defined(_NEED_ATOUL)
|
|
|
|
|
_ATOI_IMPL(atoul, ulong, strtoul)
|
|
|
|
|
#else
|
|
|
|
|
#error "What am I supposed to declare?"
|
|
|
|
|
#endif
|
|
|
|
|
|