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>
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;
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. */