implement atoi36 with strtol

This commit is contained in:
Enno Rehling 2019-07-28 12:56:59 +02:00
parent ccda750c11
commit 5cf680997e

View file

@ -21,12 +21,20 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#include "log.h" #include "log.h"
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <ctype.h> #include <ctype.h>
#define USE_STRTOL
#ifdef USE_STRTOL
int atoi36(const char *str)
{
assert(str);
return (int)strtol(str, NULL, 36);
}
#else
int atoi36(const char *str) int atoi36(const char *str)
{ {
/* cannot use strtol, because invalid strings will cause crash */
const unsigned char *s = (const unsigned char *)str; const unsigned char *s = (const unsigned char *)str;
int i = 0, sign = 1; int i = 0, sign = 1;
assert(s); assert(s);
@ -51,6 +59,7 @@ int atoi36(const char *str)
return 0; return 0;
return i * sign; return i * sign;
} }
#endif
const char *itoab_r(int i, int base, char *s, size_t len) const char *itoab_r(int i, int base, char *s, size_t len)
{ {