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