]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: tools: add a portable timegm() alternative
authorWilly Tarreau <w@1wt.eu>
Wed, 19 Jul 2017 17:05:29 +0000 (19:05 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 19 Jul 2017 17:15:06 +0000 (19:15 +0200)
commitcb1949b8b30b8db7e05546da2939eff2b5973321
tree5a6356bff45bf6f7d8a52ec9c157b9348617ef9b
parent8c2ddc20decbc927261089e330421251194cd865
MINOR: tools: add a portable timegm() alternative

timegm() is not provided everywhere and the documentation on how to
replace it is bogus as it proposes an inefficient and non-thread safe
alternative.

Here we reimplement everything needed to compute the number of seconds
since Epoch based on the broken down fields in struct tm. It is only
guaranteed to return correct values for correct inputs. It was successfully
tested with all possible 32-bit values of time_t converted to struct tm
using gmtime() and back to time_t using the legacy timegm() and this
function, and both functions always produced the same result.

Thanks to BenoĆ®t Garnier for an instructive discussion and detailed
explanations of the various time functions, leading to this solution.
include/common/standard.h
src/standard.c