]> mj.ucw.cz Git - libucw.git/commitdiff
strtonum: Fixed minor errors.
authorDaniel Fiala <danfiala@ucw.cz>
Fri, 14 May 2010 15:11:23 +0000 (17:11 +0200)
committerDaniel Fiala <danfiala@ucw.cz>
Fri, 14 May 2010 15:11:23 +0000 (17:11 +0200)
  * 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
ucw/strtonum.h

index 60dcca7b5a357be2d19ce4ec1c3fd62f836e0d6c..c21a9880297343579d51b2126ab55821a2c14db2 100644 (file)
@@ -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;
 
index b067b3fa8124e064662cacb378a6d57b68c1c65e..f4ff4f7a06d73d349a9d31e42b3ceea37b092f00 100644 (file)
@@ -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