]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: strnum - add a permissive uoff_t parser
authorPhil Carmody <phil@dovecot.fi>
Wed, 2 Jul 2014 15:21:24 +0000 (18:21 +0300)
committerPhil Carmody <phil@dovecot.fi>
Wed, 2 Jul 2014 15:21:24 +0000 (18:21 +0300)
Functions like these are so cookie-cutter, we may as well use a macro.
Note that signed helpers, if they ever appear, will need more care.

Signed-off-by: Phil Carmody <phil@dovecot.fi>
src/lib/strnum.c
src/lib/strnum.h

index a27d1f63179a33f5149bf8a2a4a687b42ed6a1f6..3ed0bc435586192750b44e3290c2b1052a685063 100644 (file)
@@ -112,6 +112,17 @@ int str_to_uintmax(const char *str, uintmax_t *num_r)
        return ret;
 }
 
+#define STR_TO_U__TEMPLATE(name, type)                         \
+int name(const char *str, type *num_r, const char **endp_r)    \
+{                                                              \
+       uintmax_t l;                                            \
+       if (str_parse_uintmax(str, &l, endp_r) < 0 || l > (type)-1)\
+               return -1;                                      \
+       *num_r = l;                                             \
+       return 0;                                               \
+}
+STR_TO_U__TEMPLATE(str_parse_uoff, uoff_t)
+
 int str_to_int(const char *str, int *num_r)
 {
        intmax_t l;
index 2edd2e2118f49efa23ee348d8673004aed8ceaf8..9044aac0b9c74f50011c3fc79627a87bdab4ee27 100644 (file)
@@ -30,6 +30,7 @@ int str_to_uid(const char *str, uid_t *num_r) ATTR_WARN_UNUSED_RESULT;
 int str_to_gid(const char *str, gid_t *num_r) ATTR_WARN_UNUSED_RESULT;
 int str_to_pid(const char *str, pid_t *num_r) ATTR_WARN_UNUSED_RESULT;
 int str_to_uoff(const char *str, uoff_t *num_r) ATTR_WARN_UNUSED_RESULT;
+int str_parse_uoff(const char *str, uoff_t *num_r, const char **endp_r) ATTR_WARN_UNUSED_RESULT ATTR_NULL(3);
 int str_to_time(const char *str, time_t *num_r) ATTR_WARN_UNUSED_RESULT;
 
 /* Returns TRUE if str is a valid unsigned number that equals to num. */