X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=libbb%2Fxatonum.c;h=a410ae9bcddece211dd29283540d22647f626cfe;hb=cdf62770af9e8bf7d5bb2344ddef8acb3216cfe2;hp=910667c14ffa3dd5c083ed45ec698e114f07d097;hpb=ed836cdc30642ddbecc286b279d461ca44135cbb;p=oweals%2Fbusybox.git diff --git a/libbb/xatonum.c b/libbb/xatonum.c index 910667c14..a410ae9bc 100644 --- a/libbb/xatonum.c +++ b/libbb/xatonum.c @@ -19,15 +19,6 @@ #define XSTR_TYPE_MIN LLONG_MIN #define XSTR_STRTOU strtoull #include "xatonum_template.c" -#undef type -#undef xstrtou -#undef xstrto -#undef xatou -#undef xato -#undef XSTR_UTYPE_MAX -#undef XSTR_TYPE_MAX -#undef XSTR_TYPE_MIN -#undef XSTR_STRTOU #if ULONG_MAX != ULLONG_MAX #define type long @@ -40,18 +31,19 @@ #define XSTR_TYPE_MIN LONG_MIN #define XSTR_STRTOU strtoul #include "xatonum_template.c" -#undef type -#undef xstrtou -#undef xstrto -#undef xatou -#undef xato -#undef XSTR_UTYPE_MAX -#undef XSTR_TYPE_MAX -#undef XSTR_TYPE_MIN -#undef XSTR_STRTOU #endif #if UINT_MAX != ULONG_MAX +static ALWAYS_INLINE +unsigned bb_strtoui(const char *str, char **end, int b) +{ + unsigned long v = strtoul(str, end, b); + if (v > UINT_MAX) { + errno = ERANGE; + return UINT_MAX; + } + return v; +} #define type int #define xstrtou(rest) xstrtou##rest #define xstrto(rest) xstrtoi##rest @@ -60,32 +52,19 @@ #define XSTR_UTYPE_MAX UINT_MAX #define XSTR_TYPE_MAX INT_MAX #define XSTR_TYPE_MIN INT_MIN -#define XSTR_STRTOU strtoul +/* libc has no strtoui, so we need to create/use our own */ +#define XSTR_STRTOU bb_strtoui #include "xatonum_template.c" -#undef type -#undef xstrtou -#undef xstrto -#undef xatou -#undef xato -#undef XSTR_UTYPE_MAX -#undef XSTR_TYPE_MAX -#undef XSTR_TYPE_MIN -#undef XSTR_STRTOU #endif /* A few special cases */ int xatoi_u(const char *numstr) { - return xatoul_range(numstr, 0, INT_MAX); -} - -uint32_t xatou32(const char *numstr) -{ - return xatoul_range(numstr, 0, 0xffffffff); + return xatou_range(numstr, 0, INT_MAX); } uint16_t xatou16(const char *numstr) { - return xatoul_range(numstr, 0, 0xffff); + return xatou_range(numstr, 0, 0xffff); }