From: Ralph Boehme Date: Wed, 4 Dec 2019 14:05:19 +0000 (+0100) Subject: lib: add time_t_to_full_timespec() X-Git-Tag: ldb-2.1.0~423 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7a69f642d7b138255a73ef42ab6dd9a5e50e5309;p=thirdparty%2Fsamba.git lib: add time_t_to_full_timespec() BUG: https://bugzilla.samba.org/show_bug.cgi?id=7771 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/lib/util/time.c b/lib/util/time.c index b69e2e02847..46d188eb897 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -1189,3 +1189,17 @@ time_t nt_time_to_full_time_t(NTTIME nt) ts = nt_time_to_full_timespec(nt); return full_timespec_to_time_t(&ts); } + +/** + * Like time_t_to_unix_timespec() but supports negative time_t values. + * + * This version converts (time_t)0 and -1 to an is_omit_timespec(), so 0 and -1 + * can't be used as valid date values. The function supports values < -1 though. + **/ +struct timespec time_t_to_full_timespec(time_t t) +{ + if (null_time(t)) { + return (struct timespec){.tv_nsec = SAMBA_UTIME_OMIT}; + } + return (struct timespec){.tv_sec = t}; +} diff --git a/lib/util/time.h b/lib/util/time.h index 77d0c08c0d8..0610710cd11 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -350,5 +350,6 @@ NTTIME full_timespec_to_nt_time(const struct timespec *ts); struct timespec nt_time_to_full_timespec(NTTIME nt); time_t full_timespec_to_time_t(const struct timespec *ts); time_t nt_time_to_full_time_t(NTTIME nt); +struct timespec time_t_to_full_timespec(time_t t); #endif /* _SAMBA_TIME_H_ */