From 097541329828425a374210da147ce818b1d40e36 Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Tue, 18 Apr 2017 13:48:18 +0200 Subject: [PATCH] MinGW: use localtime() instead of localtime_r() Fix for a1419a0806b4270bfad92ea496624b2edee5062c --- src/common.c | 6 +++++- src/common.h | 2 +- src/dir.c | 6 +++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/common.c b/src/common.c index a4458b33..2e12b072 100644 --- a/src/common.c +++ b/src/common.c @@ -167,7 +167,7 @@ char * strcasestr (const char *haystack, const char *needle) } #endif -#ifndef HAVE_LOCALTIME_R +#if ! defined(HAVE_LOCALTIME_R) && ! defined(__MINGW32__) struct tm *localtime_r(const time_t *timep, struct tm *result) { return localtime(timep); @@ -247,8 +247,12 @@ int date_dos2unix(const unsigned short f_time, const unsigned short f_date) void set_secwest(void) { const time_t t = time(NULL); +#if defined(__MINGW32__) + const struct tm *tmptr = localtime(&t); +#else struct tm tmp; const struct tm *tmptr = localtime_r(&t,&tmp); +#endif #ifdef HAVE_STRUCT_TM_TM_GMTOFF if(tmptr) secwest = -1 * tmptr->tm_gmtoff; diff --git a/src/common.h b/src/common.h index 28bad5d7..50945733 100644 --- a/src/common.h +++ b/src/common.h @@ -496,7 +496,7 @@ int strncasecmp(const char * s1, const char * s2, size_t len); #ifndef HAVE_STRCASESTR char * strcasestr (const char *haystack, const char *needle); #endif -#ifndef HAVE_LOCALTIME_R +#if ! defined(HAVE_LOCALTIME_R) && ! defined(__MINGW32__) struct tm *localtime_r(const time_t *timep, struct tm *result); #endif /* diff --git a/src/dir.c b/src/dir.c index 85b76893..7122d28d 100644 --- a/src/dir.c +++ b/src/dir.c @@ -156,9 +156,13 @@ void mode_string (const unsigned int mode, char *str) int set_datestr(char *datestr, size_t n, const time_t timev) { int test_date=0; - struct tm tmp; const struct tm *tm_p; +#if defined(__MINGW32__) + if(timev!=0 && (tm_p= localtime(&timev))!=NULL) +#else + struct tm tmp; if(timev!=0 && (tm_p= localtime_r(&timev, &tmp))!=NULL) +#endif { snprintf(datestr, n,"%2d-%s-%4d %02d:%02d", tm_p->tm_mday, monstr[tm_p->tm_mon],