Mercurial > dovecot > core-2.2
changeset 17556:dfc55d17314a
lib: strnum - add a permissive uoff_t parser
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>
author | Phil Carmody <phil@dovecot.fi> |
---|---|
date | Wed, 02 Jul 2014 18:21:24 +0300 |
parents | 85a44b4b121a |
children | 9b9b6dc7dd9b |
files | src/lib/strnum.c src/lib/strnum.h |
diffstat | 2 files changed, 12 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib/strnum.c Wed Jul 02 18:21:24 2014 +0300 +++ b/src/lib/strnum.c Wed Jul 02 18:21:24 2014 +0300 @@ -112,6 +112,17 @@ 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;
--- a/src/lib/strnum.h Wed Jul 02 18:21:24 2014 +0300 +++ b/src/lib/strnum.h Wed Jul 02 18:21:24 2014 +0300 @@ -30,6 +30,7 @@ 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. */