Navigation Menu

Skip to content

Commit

Permalink
Use gmtime_s() on MSVC
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Jan 30, 2015
1 parent 39a8807 commit 5ea8804
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 @@ -4,6 +4,7 @@ AC_CHECK_FUNCS(_stricmp)
AC_CHECK_FUNCS(_strnicmp)
AC_CHECK_FUNCS(_strtoui64)
AC_CHECK_FUNCS(close)
AC_CHECK_FUNCS(gmtime_s)
AC_CHECK_FUNCS(gmtime_r)
AC_CHECK_FUNCS(localtime_s)
AC_CHECK_FUNCS(localtime_r)
Expand Down
1 change: 1 addition & 0 deletions config.h.cmake
Expand Up @@ -141,6 +141,7 @@
#cmakedefine HAVE_CLOCK_GETTIME
#cmakedefine HAVE_CLOSE
#cmakedefine HAVE_FPCLASSIFY
#cmakedefine HAVE_GMTIME_S
#cmakedefine HAVE_GMTIME_R
#cmakedefine HAVE_LOCALTIME_R
#cmakedefine HAVE_LOCALTIME_S
Expand Down
12 changes: 9 additions & 3 deletions lib/str.c
Expand Up @@ -2441,14 +2441,20 @@ grn_text_time2rfc1123(grn_ctx *ctx, grn_obj *bulk, int sec)
{
time_t tsec;
struct tm *t;
#ifdef HAVE_GMTIME_R
#ifdef HAVE_GMTIME_S
struct tm tm;
tsec = (time_t)sec;
t = (gmtime_s(&tm, &tsec) == 0) ? &tm : NULL;
#else /* HAVE_GMTIME_S */
# ifdef HAVE_GMTIME_R
struct tm tm;
tsec = (time_t)sec;
t = gmtime_r(&tsec, &tm);
#else /* HAVE_GMTIME_R */
# else /* HAVE_GMTIME_R */
tsec = (time_t)sec;
t = gmtime(&tsec);
#endif /* HAVE_GMTIME_R */
# endif /* HAVE_GMTIME_R */
#endif /* HAVE_GMTIME_S */
if (t) {
GRN_TEXT_SET(ctx, bulk, weekdays[t->tm_wday], 3);
GRN_TEXT_PUTS(ctx, bulk, ", ");
Expand Down

0 comments on commit 5ea8804

Please sign in to comment.