os-k/kaleid/crtlib/atoi.c

38 lines
1.4 KiB
C
Raw Normal View History

2019-01-21 15:00:04 +01:00
//----------------------------------------------------------------------------//
// GNU GPL OS/K //
// //
// Authors: spectral` //
// NeoX //
// //
// Desc: Conversion utilities - atoi family //
//----------------------------------------------------------------------------//
#include <kalbase.h>
//
// String to integer
// Do not change errno
//
#define _ATOI_IMPL(_Name, _Type, _Func) \
_Type _Name(const char *str) { \
__get_errno(old); \
_Type ret = (_Type)_Func(str, NULL, 0); \
__set_errno(old); \
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