dovecot-2.2: lib: strnum - add a permissive uoff_t parser
dovecot at dovecot.org
dovecot at dovecot.org
Wed Jul 2 15:23:25 UTC 2014
details: http://hg.dovecot.org/dovecot-2.2/rev/dfc55d17314a
changeset: 17556:dfc55d17314a
user: Phil Carmody <phil at dovecot.fi>
date: Wed Jul 02 18:21:24 2014 +0300
description:
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 at dovecot.fi>
diffstat:
src/lib/strnum.c | 11 +++++++++++
src/lib/strnum.h | 1 +
2 files changed, 12 insertions(+), 0 deletions(-)
diffs (32 lines):
diff -r 85a44b4b121a -r dfc55d17314a src/lib/strnum.c
--- 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;
diff -r 85a44b4b121a -r dfc55d17314a src/lib/strnum.h
--- 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. */
More information about the dovecot-cvs
mailing list