1
0
mirror of https://gitlab.os-k.eu/os-k-team/os-k.git synced 2023-08-25 14:03:10 +02:00
os-k/kaleid/common/atoi.c

38 lines
1.4 KiB
C
Raw Normal View History

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