summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRalph Boehme <slow@samba.org>2019-12-04 12:11:05 +0100
committerJeremy Allison <jra@samba.org>2019-12-06 00:17:35 +0000
commitb5dc6aa7202957d6a68eb27150796ef669e81369 (patch)
treeeb4ca7b5e232a64f1ca703ae4fdc9bf898ca4dea /lib
parenteb42beeb1bf06aa78a67407bd74216230b8b0ef5 (diff)
downloadsamba-b5dc6aa7202957d6a68eb27150796ef669e81369.tar.gz
lib: add full_timespec_to_nt_time()
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>
Diffstat (limited to 'lib')
-rw-r--r--lib/util/time.c25
-rw-r--r--lib/util/time.h1
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/util/time.c b/lib/util/time.c
index a1a1f666506..67308444dae 100644
--- a/lib/util/time.c
+++ b/lib/util/time.c
@@ -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;
+}
diff --git a/lib/util/time.h b/lib/util/time.h
index 494b6f653ff..5c7b7b209ec 100644
--- a/lib/util/time.h
+++ b/lib/util/time.h
@@ -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_ */