]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: add full_timespec_to_nt_time()
authorRalph Boehme <slow@samba.org>
Wed, 4 Dec 2019 11:11:05 +0000 (12:11 +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 a1a1f666506b89b80461251ab45e92b904049ef7..67308444daeb27489db47143b5b194c538cb0ccd 100644 (file)
@@ -1014,3 +1014,28 @@ struct timespec make_omit_timespec(void)
 {
        return (struct timespec){.tv_nsec = SAMBA_UTIME_OMIT};
 }
+
+/**
+ * Like unix_timespec_to_nt_time() but without the special casing of tv_sec=0
+ * and -1. Also dealing with SAMBA_UTIME_OMIT.
+ **/
+NTTIME full_timespec_to_nt_time(const struct timespec *ts)
+{
+       uint64_t d;
+
+       if (ts->tv_sec == TIME_T_MAX) {
+               return 0x7fffffffffffffffLL;
+       }
+
+       if (is_omit_timespec(ts)) {
+               return 0;
+       }
+
+       d = ts->tv_sec;
+       d += TIME_FIXUP_CONSTANT_INT;
+       d *= 1000*1000*10;
+       /* d is now in 100ns units. */
+       d += (ts->tv_nsec / 100);
+
+       return d;
+}
index 494b6f653ffff38cdfdd3b7777da84497360859e..5c7b7b209ece4742906b168b550fb6d66db051e3 100644 (file)
@@ -341,5 +341,6 @@ NTTIME unix_timespec_to_nt_time(struct timespec ts);
  */
 bool is_omit_timespec(const struct timespec *ts);
 struct timespec make_omit_timespec(void);
+NTTIME full_timespec_to_nt_time(const struct timespec *ts);
 
 #endif /* _SAMBA_TIME_H_ */