From: Thomas Weißschuh Date: Fri, 6 Jan 2023 14:36:37 +0000 (+0000) Subject: strutils: add function strtotimespec_or_err X-Git-Tag: v2.39-rc1~190^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=937cd872a987a9a69f6a075c7ea9d594d9858d99;p=thirdparty%2Futil-linux.git strutils: add function strtotimespec_or_err --- diff --git a/include/strutils.h b/include/strutils.h index 34822e72bb..a51459f86f 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -48,6 +48,8 @@ extern long double strtold_or_err(const char *str, const char *errmesg); extern void strtotimeval_or_err(const char *str, struct timeval *tv, const char *errmesg); +extern void strtotimespec_or_err(const char *str, struct timespec *ts, + const char *errmesg); extern time_t strtotime_or_err(const char *str, const char *errmesg); extern int isdigit_strend(const char *str, const char **end); diff --git a/lib/strutils.c b/lib/strutils.c index 6d863b85f6..f6f299db4c 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -500,6 +500,15 @@ void strtotimeval_or_err(const char *str, struct timeval *tv, const char *errmes tv->tv_usec = (suseconds_t)((user_input - tv->tv_sec) * 1000000); } +void strtotimespec_or_err(const char *str, struct timespec *ts, const char *errmesg) +{ + long double user_input; + + user_input = strtold_or_err(str, errmesg); + ts->tv_sec = (time_t) user_input; + ts->tv_nsec = (long)((user_input - ts->tv_sec) * 1000000000); +} + time_t strtotime_or_err(const char *str, const char *errmesg) { int64_t user_input;