From: Ralph Boehme Date: Thu, 5 Dec 2019 14:07:51 +0000 (+0100) Subject: lib: add nt_time_to_full_time_t() X-Git-Tag: ldb-2.1.0~426 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2e687d0e4dba9a0f94e532726e1f3dceaa3ed840;p=thirdparty%2Fsamba.git lib: add nt_time_to_full_time_t() 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 05918a94ea5..89f9a45dd61 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -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); +} diff --git a/lib/util/time.h b/lib/util/time.h index b9bd67499f6..725be9d8cec 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -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_ */