diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-27 14:43:21 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-11-27 14:43:21 +0000 |
commit | d686a045c8134d3a42fa5cc6b2e09118e08d603f (patch) | |
tree | 38f509fc9556f68f758c77b06b480cc33b2725eb /include | |
parent | 8a0a83d503a7971895254efa9e79cf15ba1850d4 (diff) | |
download | busybox-d686a045c8134d3a42fa5cc6b2e09118e08d603f.tar.gz |
safe_strtoXX interface proved to be a bit unconvenient.
Remove it, introduce saner bb_strtoXX.
Saved ~350 bytes.
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 33 | ||||
-rw-r--r-- | include/xatonum.h | 51 |
2 files changed, 62 insertions, 22 deletions
diff --git a/include/libbb.h b/include/libbb.h index e93031231..63748c85d 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -85,30 +85,31 @@ /* CONFIG_LFS is on */ # if ULONG_MAX > 0xffffffff /* "long" is long enough on this system */ -# define STRTOOFF strtol -# define SAFE_STRTOOFF safe_strtol -# define XSTRTOUOFF xstrtoul +# define XSTRTOOFF xstrtoul +/* usage: sz = BB_STRTOOFF(s, NULL, 10); if (errno || sz < 0) die(); */ +# define BB_STRTOOFF bb_strtoul +# define STRTOOFF strtoul /* usage: printf("size: %"OFF_FMT"d (%"OFF_FMT"x)\n", sz, sz); */ # define OFF_FMT "l" # else /* "long" is too short, need "long long" */ -# define STRTOOFF strtoll -# define SAFE_STRTOOFF safe_strtoll -# define XSTRTOUOFF xstrtoull +# define XSTRTOOFF xstrtoull +# define BB_STRTOOFF bb_strtoull +# define STRTOOFF strtoull # define OFF_FMT "ll" # endif #else # if 0 /* #if UINT_MAX == 0xffffffff */ /* Doesn't work. off_t is a long. gcc will throw warnings on printf("%d", off_t) * even if long==int on this arch. Crap... */ +# define XSTRTOOFF xstrtou +# define BB_STRTOOFF bb_strtoi # define STRTOOFF strtol -# define SAFE_STRTOOFF safe_strtoi -# define XSTRTOUOFF xstrtou # define OFF_FMT "" # else +# define XSTRTOOFF xstrtoul +# define BB_STRTOOFF bb_strtol # define STRTOOFF strtol -# define SAFE_STRTOOFF safe_strtol -# define XSTRTOUOFF xstrtoul # define OFF_FMT "l" # endif #endif @@ -299,18 +300,6 @@ extern char *utoa(unsigned n); extern void itoa_to_buf(int n, char *buf, unsigned buflen); extern char *itoa(int n); -// FIXME: the prototype doesn't match libc strtoXX -> confusion -// FIXME: alot of unchecked strtoXXX are still in tree -// FIXME: atoi_or_else(str, N)? -extern int safe_strtoi(const char *arg, int* value); -extern int safe_strtou(const char *arg, unsigned* value); -extern int safe_strtod(const char *arg, double* value); -extern int safe_strtol(const char *arg, long* value); -extern int safe_strtoll(const char *arg, long long* value); -extern int safe_strtoul(const char *arg, unsigned long* value); -extern int safe_strtoull(const char *arg, unsigned long long* value); -extern int safe_strtou32(const char *arg, uint32_t* value); - struct suffix_mult { const char *suffix; unsigned mult; diff --git a/include/xatonum.h b/include/xatonum.h index 46e49b0eb..585d84623 100644 --- a/include/xatonum.h +++ b/include/xatonum.h @@ -104,3 +104,54 @@ extern inline uint32_t xatou32(const char *numstr) return xatoul(numstr); return BUG_xatou32_unimplemented(); } + +/* Non-aborting kind of convertors */ + +unsigned long long bb_strtoull(const char *arg, char **endp, int base); +long long bb_strtoll(const char *arg, char **endp, int base); + +#if ULONG_MAX == ULLONG_MAX +extern inline +unsigned long bb_strtoul(const char *arg, char **endp, int base) +{ return bb_strtoull(arg, endp, base); } +extern inline +unsigned long bb_strtol(const char *arg, char **endp, int base) +{ return bb_strtoll(arg, endp, base); } +#else +unsigned long bb_strtoul(const char *arg, char **endp, int base); +long bb_strtol(const char *arg, char **endp, int base); +#endif + +#if UINT_MAX == ULLONG_MAX +extern inline +unsigned long bb_strtou(const char *arg, char **endp, int base) +{ return bb_strtoull(arg, endp, base); } +extern inline +unsigned long bb_strtoi(const char *arg, char **endp, int base) +{ return bb_strtoll(arg, endp, base); } +#elif UINT_MAX == ULONG_MAX +extern inline +unsigned long bb_strtou(const char *arg, char **endp, int base) +{ return bb_strtoul(arg, endp, base); } +extern inline +unsigned long bb_strtoi(const char *arg, char **endp, int base) +{ return bb_strtol(arg, endp, base); } +#else +unsigned long bb_strtou(const char *arg, char **endp, int base); +long bb_strtoi(const char *arg, char **endp, int base); +#endif + +int BUG_bb_strtou32_unimplemented(void); +extern inline +uint32_t bb_strtou32(const char *arg, char **endp, int base) +{ + if (sizeof(uint32_t) == sizeof(unsigned)) + return bb_strtou(arg, endp, base); + if (sizeof(uint32_t) == sizeof(unsigned long)) + return bb_strtoul(arg, endp, base); + return BUG_bb_strtou32_unimplemented(); +} + +/* Floating point */ + +/* double bb_strtod(const char *arg, char **endp); */ |