diff options
author | Allen Winter <allen.winter@kdab.com> | 2015-05-19 19:44:09 -0400 |
---|---|---|
committer | Allen Winter <allen.winter@kdab.com> | 2015-05-19 19:44:09 -0400 |
commit | 92f39ba83116ee67ab43a43458e94542ee878fb3 (patch) | |
tree | 374dcd1e397340487290f69771bcd836149e5a65 | |
parent | b6cb79f91e74c89877e5767e6810251df012f44b (diff) | |
download | libical-git-92f39ba83116ee67ab43a43458e94542ee878fb3.tar.gz |
use gmtime_r consistently (on Windows it is a wrapper on gmtime())
gmtime() on Windows is thread-safe.
-rw-r--r-- | ConfigureChecks.cmake | 2 | ||||
-rw-r--r-- | config.h.cmake | 33 | ||||
-rw-r--r-- | src/libical/icaltime.c | 19 | ||||
-rw-r--r-- | src/libical/icaltimezone.c | 9 | ||||
-rw-r--r-- | src/libicalvcal/icalvcal.c | 16 | ||||
-rw-r--r-- | src/test/regression-utils.c | 13 |
6 files changed, 30 insertions, 62 deletions
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake index 00448dde..755a41db 100644 --- a/ConfigureChecks.cmake +++ b/ConfigureChecks.cmake @@ -4,11 +4,9 @@ check_include_files(dirent.h HAVE_DIRENT_H) check_include_files(endian.h HAVE_ENDIAN_H) check_include_files(inttypes.h HAVE_INTTYPES_H) check_include_files(pthread.h HAVE_PTHREAD_H) -check_include_files(stdint.h HAVE_STDINT_H) check_include_files(sys/endian.h HAVE_SYS_ENDIAN_H) check_include_files(sys/param.h HAVE_SYS_PARAM_H) check_include_files(sys/utsname.h HAVE_SYS_UTSNAME_H) -check_include_files(time.h HAVE_TIME_H) check_include_files(fcntl.h HAVE_FCNTL_H) check_include_files(unistd.h HAVE_UNISTD_H) check_include_files(wctype.h HAVE_WCTYPE_H) diff --git a/config.h.cmake b/config.h.cmake index 1a842b48..5faed9e2 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -54,9 +54,6 @@ /* Define to 1 if you have the `_stat' function. */ #cmakedefine HAVE__STAT 1 -/* Define to 1 if you have the <stdint.h> header file. */ -#cmakedefine HAVE_STDINT_H 1 - /* Define to 1 if you have the `strcasecmp' function. */ #cmakedefine HAVE_STRCASECMP 1 @@ -123,9 +120,6 @@ /* Define to 1 if you have the <sys/utsname.h> header file. */ #cmakedefine HAVE_SYS_UTSNAME_H 1 -/* Define to 1 if you have the <time.h> header file. */ -#cmakedefine HAVE_TIME_H 1 - /* Define to 1 if you have the <unistd.h> header file. */ #cmakedefine HAVE_UNISTD_H 1 @@ -157,9 +151,6 @@ /* Define to prevent empty properties from being replaced with X-LIC-ERROR properties */ #define ICAL_ALLOW_EMPTY_PROPERTIES ${ICAL_ALLOW_EMPTY_PROPERTIES} -/* Define if we want _REENTRANT */ -#cmakedefine ICAL_REENTRANT 1 - /* Define to 1 if you DO NOT WANT to see deprecated messages */ #define NO_WARN_DEPRECATED ${NO_WARN_DEPRECATED} @@ -178,19 +169,9 @@ /* Define to the version of this package. */ #define PACKAGE_VERSION "${PROJECT_VERSION}" -/* Define to 1 if you have the ANSI C header files. */ -#cmakedefine STDC_HEADERS 1 - -/* Define to 1 if your <sys/time.h> declares `struct tm'. */ -#cmakedefine TM_IN_SYS_TIME 1 - /* whether we should bring our own TZ-Data */ #cmakedefine USE_BUILTIN_TZDATA -/* Define to 1 if `lex' declares `yytext' as a `char *' by default, not a - `char[]'. */ -#cmakedefine YYTEXT_POINTER 1 - /* Define to empty if `const' does not conform to ANSI C. */ #cmakedefine const @@ -440,6 +421,20 @@ typedef ssize_t IO_SSIZE_T; #endif #endif +/* gmtime_r - thread safe gmtime() really only need on Unix */ +#if !defined(HAVE_GMTIME_R) +#if !defined(_WIN32) +#error "No thread-safe gmtime function available" +#endif +/*on Windows there might be a macro called gmtime_r in pthread.h. don't use it.*/ +#if defined(gmtime_r) +#undef gmtime_r +#endif +/* FYI: The gmtime() in Microsoft's C library is MT-safe */ +#define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0) +#endif +#include <time.h> + /* define MAXPATHLEN */ #if defined(_WIN32) #include <windows.h> //for MAX_PATH diff --git a/src/libical/icaltime.c b/src/libical/icaltime.c index dda44782..8f922f71 100644 --- a/src/libical/icaltime.c +++ b/src/libical/icaltime.c @@ -32,16 +32,6 @@ #include <stdlib.h> -#if defined(_WIN32) -/* Undef the similar macro from pthread.h, it doesn't check if - * gmtime() returns NULL. - */ -#undef gmtime_r - -/* The gmtime() in Microsoft's C library is MT-safe */ -#define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0) -#endif - #if defined(HAVE_PTHREAD) #include <pthread.h> static pthread_mutex_t tzid_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -183,13 +173,8 @@ icaltime_from_timet_with_zone(const time_t tm, const int is_date, utc_zone = icaltimezone_get_utc_timezone (); - /* Convert the time_t to a struct tm in UTC time. We can trust gmtime - for this. */ -#if defined(HAVE_PTHREAD) - gmtime_r (&tm, &t); -#else - t = *(gmtime (&tm)); -#endif + /* Convert the time_t to a struct tm in UTC time. We can trust gmtime for this. */ + gmtime_r(&tm, &t); tt.year = t.tm_year + 1900; tt.month = t.tm_mon + 1; diff --git a/src/libical/icaltimezone.c b/src/libical/icaltimezone.c index 053341d2..9bc90ea6 100644 --- a/src/libical/icaltimezone.c +++ b/src/libical/icaltimezone.c @@ -45,11 +45,6 @@ static pthread_mutex_t builtin_mutex = PTHREAD_MUTEX_INITIALIZER; #include <mbstring.h> #endif #include <windows.h> -/* Undef the similar macro from pthread.h, it doesn't check if gmtime() returns NULL. */ -#undef gmtime_r - -/* The gmtime() in Microsoft's C library is MT-safe */ -#define gmtime_r(tp,tmp) (gmtime(tp)?(*(tmp)=*gmtime(tp),(tmp)):0) #endif /** This is the toplevel directory where the timezone data is installed in. */ @@ -1439,9 +1434,9 @@ get_offset (icaltimezone *zone) struct tm local; struct icaltimetype tt; int offset; - time_t now = time(NULL); + const time_t now = time(NULL); - gmtime_r ((const time_t *) &now, &local); + gmtime_r(&now, &local); tt = tm_to_icaltimetype (&local); offset = icaltimezone_get_utc_offset(zone, &tt, NULL); diff --git a/src/libicalvcal/icalvcal.c b/src/libicalvcal/icalvcal.c index 9732cc3e..e3907abe 100644 --- a/src/libicalvcal/icalvcal.c +++ b/src/libicalvcal/icalvcal.c @@ -118,7 +118,7 @@ static char* get_string_value (VObject *object, int *free_string) static void convert_floating_time_to_utc (struct icaltimetype *itt) { - struct tm tmp_tm, *utc_tm; + struct tm tmp_tm, utc_tm; time_t t; /* We assume the floating time is using the current Unix timezone. @@ -136,15 +136,15 @@ static void convert_floating_time_to_utc (struct icaltimetype *itt) t = mktime (&tmp_tm); /* Now convert back to a struct tm, but with a UTC time. */ - utc_tm = gmtime (&t); + gmtime_r(&t, &utc_tm); /* Now put it back into the icaltime. */ - itt->year = utc_tm->tm_year + 1900; - itt->month = utc_tm->tm_mon + 1; - itt->day = utc_tm->tm_mday; - itt->hour = utc_tm->tm_hour; - itt->minute = utc_tm->tm_min; - itt->second = utc_tm->tm_sec; + itt->year = utc_tm.tm_year + 1900; + itt->month = utc_tm.tm_mon + 1; + itt->day = utc_tm.tm_mday; + itt->hour = utc_tm.tm_hour; + itt->minute = utc_tm.tm_min; + itt->second = utc_tm.tm_sec; /* Set the is_utc flag. */ itt->is_utc = 1; diff --git a/src/test/regression-utils.c b/src/test/regression-utils.c index f1f27623..60e4502f 100644 --- a/src/test/regression-utils.c +++ b/src/test/regression-utils.c @@ -13,16 +13,11 @@ static char ictt_str[1024]; const char* ical_timet_string(const time_t t) { - struct tm stm; - struct tm *tmp = gmtime(&t); + struct tm tmp; + gmtime_r(&t, &tmp); - if (tmp) - stm = *tmp; - else - memset(&stm, 0, sizeof(stm)); - - sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d Z",stm.tm_year+1900, - stm.tm_mon+1,stm.tm_mday,stm.tm_hour,stm.tm_min,stm.tm_sec); + sprintf(ictt_str,"%02d-%02d-%02d %02d:%02d:%02d Z",tmp.tm_year+1900, + tmp.tm_mon+1,tmp.tm_mday,tmp.tm_hour,tmp.tm_min,tmp.tm_sec); return ictt_str; |