From 74b36cea52267a0b1f2d7230ff3a52e538fd5372 Mon Sep 17 00:00:00 2001 From: Vincent Torri Date: Fri, 30 Apr 2021 14:12:48 +0200 Subject: [PATCH] Use Windows localtime_s() if available If available, use localtime_s() instead of localtime(). As localtime_s() is part of the Windows API, the compile check with localtime_s() should only work for those systems. Note we are not using AC_CANONICAL_HOST and then checking the $host_os here. Either localtime_s() is available, then we can use it. Or localtime_s() is not available, then we cannot use it. All of that is independent of what exactly the $host_os value actually is, and whether we have listed all appropriate values in the list of matches. Closes: https://github.com/libexif/libexif/issues/57 Closes: https://github.com/libexif/libexif/pull/66 --- configure.ac | 14 ++++++++++++++ libexif/exif-entry.c | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ab5af3bd..138eb87e 100644 --- a/configure.ac +++ b/configure.ac @@ -208,8 +208,22 @@ GP_GETTEXT_FLAGS() dnl --------------------------------------------------------------------------- dnl Thread-safe functions dnl --------------------------------------------------------------------------- +AC_MSG_CHECKING([for localtime_s]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([[ + #include +]], [[ + localtime_s(NULL, NULL); +]])], [dnl + have_localtime_s="yes" + AC_DEFINE([HAVE_LOCALTIME_S], [1], [Define to 1 if you have localtime_s()]) +], [dnl + have_localtime_s="no" +]) +AC_MSG_RESULT([$have_localtime_s]) + AC_CHECK_FUNCS([localtime_r]) + dnl --------------------------------------------------------------------------- dnl Compiler/Linker Options and Warnings dnl --------------------------------------------------------------------------- diff --git a/libexif/exif-entry.c b/libexif/exif-entry.c index d08b2dbb..89744f34 100644 --- a/libexif/exif-entry.c +++ b/libexif/exif-entry.c @@ -1641,7 +1641,7 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag) case EXIF_TAG_DATE_TIME_DIGITIZED: { time_t t; -#ifdef HAVE_LOCALTIME_R +#if defined(HAVE_LOCALTIME_R) || defined(HAVE_LOCALTIME_S) struct tm tms; #endif struct tm *tm; @@ -1649,6 +1649,9 @@ exif_entry_initialize (ExifEntry *e, ExifTag tag) t = time (NULL); #ifdef HAVE_LOCALTIME_R tm = localtime_r (&t, &tms); +#elif HAVE_LOCALTIME_S + localtime_s (&tms, &t); + tm = &tms; #else tm = localtime (&t); #endif