Navigation Menu

Skip to content

Commit

Permalink
Use localtime_s() on MSVC
Browse files Browse the repository at this point in the history
GitHub: fix #237

Patch by Susumu Yata. Thanks!!!
  • Loading branch information
kou committed Jan 30, 2015
1 parent fbdefbc commit 39a8807
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/ac_macros/check_functions.m4
Expand Up @@ -5,6 +5,7 @@ AC_CHECK_FUNCS(_strnicmp)
AC_CHECK_FUNCS(_strtoui64)
AC_CHECK_FUNCS(close)
AC_CHECK_FUNCS(gmtime_r)
AC_CHECK_FUNCS(localtime_s)
AC_CHECK_FUNCS(localtime_r)
AC_CHECK_FUNCS(mkostemp)
AC_CHECK_FUNCS(open)
Expand Down
1 change: 1 addition & 0 deletions config.h.cmake
Expand Up @@ -143,6 +143,7 @@
#cmakedefine HAVE_FPCLASSIFY
#cmakedefine HAVE_GMTIME_R
#cmakedefine HAVE_LOCALTIME_R
#cmakedefine HAVE_LOCALTIME_S
#cmakedefine HAVE_MKOSTEMP
#cmakedefine HAVE_OPEN
#cmakedefine HAVE_READ
Expand Down
12 changes: 9 additions & 3 deletions lib/ctx.c
Expand Up @@ -133,14 +133,20 @@ grn_rc
grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf)
{
struct tm *ltm;
#ifdef HAVE_LOCALTIME_R
#ifdef HAVE_LOCALTIME_S
struct tm tm;
time_t t = tv->tv_sec;
ltm = (localtime_s(&tm, &t) == 0) ? &tm : NULL;
#else /* HAVE_LOCALTIME_S */
# ifdef HAVE_LOCALTIME_R
struct tm tm;
time_t t = tv->tv_sec;
ltm = localtime_r(&t, &tm);
#else /* HAVE_LOCALTIME_R */
# else /* HAVE_LOCALTIME_R */
time_t tvsec = (time_t) tv->tv_sec;
ltm = localtime(&tvsec);
#endif /* HAVE_LOCALTIME_R */
# endif /* HAVE_LOCALTIME_R */
#endif /* HAVE_LOCALTIME_S */
if (!ltm) { SERR("localtime"); }
snprintf(buf, GRN_TIMEVAL_STR_SIZE - 1, GRN_TIMEVAL_STR_FORMAT,
ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday,
Expand Down

0 comments on commit 39a8807

Please sign in to comment.