From: Timo Sirainen Date: Thu, 8 Dec 2011 07:28:54 +0000 (+0200) Subject: liblib: Added str_to_time() X-Git-Tag: 2.1.rc2~75 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=076f8c12cfa4c8d30695f94f389c670d89e200fa;p=thirdparty%2Fdovecot%2Fcore.git liblib: Added str_to_time() --- diff --git a/src/lib/strnum.c b/src/lib/strnum.c index 2eb16e9ed4..1edea2cb1d 100644 --- a/src/lib/strnum.c +++ b/src/lib/strnum.c @@ -233,6 +233,17 @@ int str_to_uoff(const char *str, uoff_t *num_r) return 0; } +int str_to_time(const char *str, time_t *num_r) +{ + intmax_t l; + + if (str_to_intmax(str, &l) < 0) + return -1; + + *num_r = (time_t)l; + return 0; +} + bool str_uint_equals(const char *str, uintmax_t num) { uintmax_t l; diff --git a/src/lib/strnum.h b/src/lib/strnum.h index cd56de03f9..703286da65 100644 --- a/src/lib/strnum.h +++ b/src/lib/strnum.h @@ -24,6 +24,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_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. */ bool str_uint_equals(const char *str, uintmax_t num);