From 863b8193b9cff85ac027c78fbcc2f3d9441e126e Mon Sep 17 00:00:00 2001 From: Daniel Fiala Date: Fri, 14 May 2010 17:11:23 +0200 Subject: [PATCH] strtonum: Fixed minor errors. * Removed declarations of undefined conversion functions. * Added inline conversion functions for signed integers. * Moved branche for checking whether number is terminated by 0 character. --- ucw/strtonum-gen.h | 10 +++++----- ucw/strtonum.h | 13 ++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/ucw/strtonum-gen.h b/ucw/strtonum-gen.h index 60dcca7b..c21a9880 100644 --- a/ucw/strtonum-gen.h +++ b/ucw/strtonum-gen.h @@ -68,11 +68,6 @@ STN_DECLARE(STN_TYPE, STN_SUFFIX) if (!overflow) { - if ((flags & STN_ZCHAR) && *p) - { - return err_invalid_character; - } - if (!digits) { return err_no_digits; @@ -93,6 +88,11 @@ STN_DECLARE(STN_TYPE, STN_SUFFIX) } } + if ((flags & STN_ZCHAR) && *p) + { + return err_invalid_character; + } + if (num) *num = val; diff --git a/ucw/strtonum.h b/ucw/strtonum.h index b067b3fa..f4ff4f7a 100644 --- a/ucw/strtonum.h +++ b/ucw/strtonum.h @@ -31,12 +31,19 @@ enum str_to_num_flags { #define STN_SFLAGS (STN_FLAGS | STN_SIGNED) #define STN_USFLAGS (STN_SFLAGS | STN_UNDERSCORE) -#define STN_DECLARE_CONVERTOR(type, suffix) \ +#define STN_DECLARE_CONVERTOR(type, suffix) \ const char *str_to_##suffix(type *num, const char *str, const char **next, const uns flags) +#define STN_SIGNED_CONVERTOR(utype, itype, suffix) \ +static inline const char *str_to_##suffix(itype *num, const char *str, const char **next, const uns flags) \ +{ \ + return str_to##suffix((utype*) num, str, next, flags | STN_SIGNED); \ +} + STN_DECLARE_CONVERTOR(uns, uns); -STN_DECLARE_CONVERTOR(long, long); +STN_SIGNED_CONVERTOR(uns, int, int) + STN_DECLARE_CONVERTOR(uintmax_t, uintmax); -STN_DECLARE_CONVERTOR(unsigned long long, ull); +STN_SIGNED_CONVERTOR(uintmax_t, intmax_t, intmax) #endif -- 2.39.2