lib: add nt_time_to_full_time_t()
authorRalph Boehme <slow@samba.org>
Thu, 5 Dec 2019 14:07:51 +0000 (15:07 +0100)
committerJeremy Allison <jra@samba.org>
Fri, 6 Dec 2019 00:17:35 +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 05918a94ea5f3b654ca551eb096bdda7d6125ea5..89f9a45dd612274a80c929f2361db16538be7d0e 100644 (file)
@@ -1116,3 +1116,20 @@ time_t full_timespec_to_time_t(const struct timespec *_ts)
        }
        return ts.tv_sec;
 }
+
+/**
+ * Like nt_time_to_unix() but supports negative time_t values.
+ *
+ * Note: this function uses the full time_t range as valid date values including
+ * (time_t)0 and -1. That means that NTTIME sentinel values of 0 and -1 which
+ * represent a "not-set" value, can't be converted to sentinel values in a
+ * time_t representation. Callers should therefor check the NTTIME value with
+ * null_nttime() before calling this function.
+ **/
+time_t nt_time_to_full_time_t(NTTIME nt)
+{
+       struct timespec ts;
+
+       ts = nt_time_to_full_timespec(nt);
+       return full_timespec_to_time_t(&ts);
+}
index b9bd67499f6ba3b103f7ef0fecbf564da4385a39..725be9d8cec72a00c8f7bd6011369255231d778b 100644 (file)
@@ -344,5 +344,6 @@ struct timespec make_omit_timespec(void);
 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);
 
 #endif /* _SAMBA_TIME_H_ */