Skip to content

Commit

Permalink
Use Windows localtime_s() if available
Browse files Browse the repository at this point in the history
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: #57
Closes: #66
  • Loading branch information
vtorri authored and ndim committed May 28, 2021
1 parent 6a37f5f commit 74b36ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
14 changes: 14 additions & 0 deletions configure.ac
Expand Up @@ -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 <time.h>
]], [[
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 ---------------------------------------------------------------------------
Expand Down
5 changes: 4 additions & 1 deletion libexif/exif-entry.c
Expand Up @@ -1641,14 +1641,17 @@ 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;

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
Expand Down

0 comments on commit 74b36ce

Please sign in to comment.