From: Ralph Boehme Date: Wed, 4 Dec 2019 11:11:05 +0000 (+0100) Subject: lib: add full_timespec_to_nt_time() X-Git-Tag: ldb-2.1.0~430 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b5dc6aa7202957d6a68eb27150796ef669e81369;p=thirdparty%2Fsamba.git lib: add full_timespec_to_nt_time() BUG: https://bugzilla.samba.org/show_bug.cgi?id=7771 Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- 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_ */