From 95f862fdd82a99e30bbf2c43009ec9a51e416804 Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Thu, 13 Feb 2020 16:30:05 -0500 Subject: parse: Handle 1969-12-31T23:59:59Z mktime() returns -1 on error, but also for one second before the epoch. Compare the input against localtime(-1) to distinguish those cases. --- util.h | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'util.h') diff --git a/util.h b/util.h index ef546d4..ae12703 100644 --- a/util.h +++ b/util.h @@ -181,15 +181,29 @@ int xlocaltime(const time_t *timep, struct tm *result); */ int xgmtime(const time_t *timep, struct tm *result); +/** + * mktime() wrapper that reports errors more reliably. + * + * @param[in,out] tm + * The struct tm to convert. + * @param[out] timep + * Where to store the result. + * @return + * 0 on success, -1 on failure. + */ +int xmktime(struct tm *tm, time_t *timep); + /** * A portable timegm(), the inverse of gmtime(). * - * @param tm + * @param[in,out] tm * The struct tm to convert. + * @param[out] timep + * Where to store the result. * @return - * The converted time on success, or -1 on failure. + * 0 on success, -1 on failure. */ -time_t xtimegm(struct tm *tm); +int xtimegm(struct tm *tm, time_t *timep); /** * Format a mode like ls -l (e.g. -rw-r--r--). -- cgit v1.2.3