From 937cd872a987a9a69f6a075c7ea9d594d9858d99 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Thomas=20Wei=C3=9Fschuh?= Date: Fri, 6 Jan 2023 14:36:37 +0000 Subject: [PATCH] strutils: add function strtotimespec_or_err --- include/strutils.h | 2 ++ lib/strutils.c | 9 +++++++++ 2 files changed, 11 insertions(+) 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; -- 2.47.3