]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: add time_t_to_full_timespec()
authorRalph Boehme <slow@samba.org>
Wed, 4 Dec 2019 14:05:19 +0000 (15:05 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 6 Dec 2019 00:17:36 +0000 (00:17 +0000)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=7771

Signed-off-by: Ralph Boehme <slow@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/time.c
lib/util/time.h

index b69e2e02847e2c818c584ada92addc4100020841..46d188eb897a7de2831df1850318a48b79d9c76e 100644 (file)
@@ -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};
+}
index 77d0c08c0d8981dbf45754055166f759fab51f09..0610710cd11f29cc5b15e4e2eb4090c3c37e6429 100644 (file)
@@ -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_ */