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_ */