From 43bddf31e95080abf7232952da9064207636f47b Mon Sep 17 00:00:00 2001 From: Denis Vlasenko Date: Sat, 25 Nov 2006 14:49:04 +0000 Subject: small improvements in str -> num convertors --- libbb/xatonum.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'libbb/xatonum.c') diff --git a/libbb/xatonum.c b/libbb/xatonum.c index 910667c14..0d487dd9b 100644 --- a/libbb/xatonum.c +++ b/libbb/xatonum.c @@ -52,6 +52,15 @@ #endif #if UINT_MAX != ULONG_MAX +extern 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,7 +69,8 @@ #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 @@ -77,7 +87,7 @@ int xatoi_u(const char *numstr) { - return xatoul_range(numstr, 0, INT_MAX); + return xatou_range(numstr, 0, INT_MAX); } uint32_t xatou32(const char *numstr) @@ -87,5 +97,5 @@ uint32_t xatou32(const char *numstr) uint16_t xatou16(const char *numstr) { - return xatoul_range(numstr, 0, 0xffff); + return xatou_range(numstr, 0, 0xffff); } -- cgit v1.2.3