lib: util: Add a function nt_time_to_unix_timespec_raw().
authorJeremy Allison <jra@samba.org>
Thu, 6 Jan 2022 21:58:20 +0000 (13:58 -0800)
committerJeremy Allison <jra@samba.org>
Sat, 8 Jan 2022 05:43:32 +0000 (05:43 +0000)
Not yet used. Does no checks on the converted values.

A later cleanup will allow us to move nt_time_to_unix_timespec()
and nt_time_to_full_timespec() to use common code.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14928

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Christof Schmitt <cs@samba.org>
lib/util/time.c
lib/util/time.h

index cec91c1479118bbbe0259edf1f0066871b1027ad..5839e80a15b25af3c8569415156a7f12f47eaf40 100644 (file)
@@ -867,6 +867,36 @@ _PUBLIC_ int get_time_zone(time_t t)
        return tm_diff(&tm_utc,tm);
 }
 
+/*
+ * Raw convert an NTTIME to a unix timespec.
+ */
+
+struct timespec nt_time_to_unix_timespec_raw(
+                       NTTIME nt)
+{
+       int64_t d;
+       struct timespec ret;
+
+       d = (int64_t)nt;
+       /* d is now in 100ns units, since jan 1st 1601".
+          Save off the ns fraction. */
+
+       /*
+        * Take the last seven decimal digits and multiply by 100.
+        * to convert from 100ns units to 1ns units.
+        */
+        ret.tv_nsec = (long) ((d % (1000 * 1000 * 10)) * 100);
+
+       /* Convert to seconds */
+       d /= 1000*1000*10;
+
+       /* Now adjust by 369 years to make the secs since 1970 */
+       d -= TIME_FIXUP_CONSTANT_INT;
+
+       ret.tv_sec = (time_t)d;
+       return ret;
+}
+
 struct timespec nt_time_to_unix_timespec(NTTIME nt)
 {
        int64_t d;
index 72347b39b994cbfdea869f108e5592c64adc86a0..bdb67de54317a0ba2ad7bc06823d94e950260355 100644 (file)
@@ -343,6 +343,8 @@ bool nt_time_equal(NTTIME *t1, NTTIME *t2);
 
 void interpret_dos_date(uint32_t date,int *year,int *month,int *day,int *hour,int *minute,int *second);
 
+struct timespec nt_time_to_unix_timespec_raw(NTTIME nt);
+
 struct timespec nt_time_to_unix_timespec(NTTIME nt);
 
 time_t convert_timespec_to_time_t(struct timespec ts);