Skip to content

Commit

Permalink
include/timehead.h: fix hacky macro localtime_*() fallbacks for WIN32…
Browse files Browse the repository at this point in the history
… builds [#2583, #1611]

Partially inspired by /mingw64/include/time.h

NOTE: Unlike linux+mingw cross-builds, the semi-native ones on
Windows with MSYS2 do not enforce _POSIX_THREAD_SAFE_FUNCTIONS
and so can lack the optional declarations in the file above.

Signed-off-by: Jim Klimov <[email protected]>
  • Loading branch information
jimklimov committed Aug 5, 2024
1 parent 8402660 commit 3113697
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions include/timehead.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ char * strptime(const char *buf, const char *fmt, struct tm *tm);

#if !(defined HAVE_LOCALTIME_R && HAVE_LOCALTIME_R) && !(defined HAVE_DECL_LOCALTIME_R && HAVE_DECL_LOCALTIME_R)
# if (defined HAVE_LOCALTIME_S && HAVE_LOCALTIME_S) || (defined HAVE_DECL_LOCALTIME_S && HAVE_DECL_LOCALTIME_S)
/* A bit of a silly trick, but should help on MSYS2 builds it seems */
# define localtime_r(timer, buf) localtime_s(timer, buf)
/* A bit of a silly trick, but should help on MSYS2 builds it seems
* errno_t localtime_s(struct tm *_Tm, const time_t *_Time)
*/
# define localtime_r(timer, buf) (localtime_s(buf, timer) ? NULL : buf)
# else
# include <string.h> /* memcpy */
static inline struct tm *localtime_r( const time_t *timer, struct tm *buf ) {
Expand All @@ -61,7 +63,8 @@ static inline struct tm *localtime_r( const time_t *timer, struct tm *buf ) {

#if !(defined HAVE_GMTIME_R && HAVE_GMTIME_R) && !(defined HAVE_DECL_GMTIME_R && HAVE_DECL_GMTIME_R)
# if (defined HAVE_GMTIME_S && HAVE_GMTIME_S) || (defined HAVE_DECL_GMTIME_S && HAVE_DECL_GMTIME_S)
# define gmtime_r(timer, buf) gmtime_s(timer, buf)
/* See comment above */
# define gmtime_r(timer, buf) (gmtime_s(buf, timer) ? NULL : buf)
# else
# include <string.h> /* memcpy */
static inline struct tm *gmtime_r( const time_t *timer, struct tm *buf ) {
Expand Down

0 comments on commit 3113697

Please sign in to comment.