os-k/kaleid/crtlib/atoi.c

36 lines
1.4 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//----------------------------------------------------------------------------//
// 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