From: Ralph Boehme Date: Tue, 26 Nov 2019 17:22:17 +0000 (+0000) Subject: lib: add functions dealing with struct timespec UTIME_OMIT X-Git-Tag: ldb-2.1.0~431 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=eb42beeb1bf06aa78a67407bd74216230b8b0ef5;p=thirdparty%2Fsamba.git lib: add functions dealing with struct timespec UTIME_OMIT 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 3a6043025f4..a1a1f666506 100644 --- a/lib/util/time.c +++ b/lib/util/time.c @@ -991,3 +991,26 @@ _PUBLIC_ NTTIME unix_timespec_to_nt_time(struct timespec ts) return d; } + +/* + * Functions supporting the full range of time_t and struct timespec values, + * including 0, -1 and all other negative values. These functions don't use 0 or + * -1 values as sentinel to denote "unset" variables, but use the POSIX 2008 + * define UTIME_OMIT from utimensat(2). + */ + +/** + * Check if it's a to be omitted timespec. + **/ +bool is_omit_timespec(const struct timespec *ts) +{ + return ts->tv_nsec == SAMBA_UTIME_OMIT; +} + +/** + * Return a to be omitted timespec. + **/ +struct timespec make_omit_timespec(void) +{ + return (struct timespec){.tv_nsec = SAMBA_UTIME_OMIT}; +} diff --git a/lib/util/time.h b/lib/util/time.h index d03dc4908f3..494b6f653ff 100644 --- a/lib/util/time.h +++ b/lib/util/time.h @@ -333,4 +333,13 @@ void round_timespec_to_usec(struct timespec *ts); void round_timespec_to_nttime(struct timespec *ts); NTTIME unix_timespec_to_nt_time(struct timespec ts); +/* + * Functions supporting the full range of time_t and struct timespec values, + * including 0, -1 and all other negative values. These functions don't use 0 or + * -1 values as sentinel to denote "unset" variables, but use the POSIX 2008 + * define UTIME_OMIT from utimensat(2). + */ +bool is_omit_timespec(const struct timespec *ts); +struct timespec make_omit_timespec(void); + #endif /* _SAMBA_TIME_H_ */