1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

lib: add time_t_to_full_timespec()

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>
This commit is contained in:
Ralph Boehme 2019-12-04 15:05:19 +01:00 committed by Jeremy Allison
parent 928694af7e
commit 7a69f642d7
2 changed files with 15 additions and 0 deletions

View File

@ -1189,3 +1189,17 @@ time_t nt_time_to_full_time_t(NTTIME nt)
ts = nt_time_to_full_timespec(nt);
return full_timespec_to_time_t(&ts);
}
/**
* Like time_t_to_unix_timespec() but supports negative time_t values.
*
* This version converts (time_t)0 and -1 to an is_omit_timespec(), so 0 and -1
* can't be used as valid date values. The function supports values < -1 though.
**/
struct timespec time_t_to_full_timespec(time_t t)
{
if (null_time(t)) {
return (struct timespec){.tv_nsec = SAMBA_UTIME_OMIT};
}
return (struct timespec){.tv_sec = t};
}

View File

@ -350,5 +350,6 @@ 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);
struct timespec time_t_to_full_timespec(time_t t);
#endif /* _SAMBA_TIME_H_ */