summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--time64.c45
-rw-r--r--time64.h6
2 files changed, 21 insertions, 30 deletions
diff --git a/time64.c b/time64.c
index 6c75c482cf..dfd5776e3a 100644
--- a/time64.c
+++ b/time64.c
@@ -289,28 +289,6 @@ static void S_copy_little_tm_to_big_TM(const struct tm *src, struct TM *dest) {
#endif
}
-
-#ifndef HAS_GMTIME_R
-/* Simulate gmtime_r() to the best of our ability */
-static struct tm * S_gmtime_r(const time_t *clock, struct tm *result) {
-#ifdef __VMS
- dTHX; /* the following is defined as Perl_my_localtime(aTHX_ ...) */
-#endif
- const struct tm * const static_result = gmtime(clock);
-
- assert(result != NULL);
-
- if( static_result == NULL ) {
- memset(result, 0, sizeof(*result));
- return NULL;
- }
- else {
- memcpy(result, static_result, sizeof(*result));
- return result;
- }
-}
-#endif
-
struct TM *Perl_gmtime64_r (const Time64_T *in_time, struct TM *p)
{
int v_tm_sec, v_tm_min, v_tm_hour, v_tm_mon, v_tm_wday;
@@ -319,6 +297,7 @@ struct TM *Perl_gmtime64_r (const Time64_T *in_time, struct TM *p)
Time64_T m;
Time64_T time = *in_time;
Year year = 70;
+ dTHX;
assert(p != NULL);
@@ -326,9 +305,27 @@ struct TM *Perl_gmtime64_r (const Time64_T *in_time, struct TM *p)
if( SHOULD_USE_SYSTEM_GMTIME(*in_time) ) {
time_t safe_time = (time_t)*in_time;
struct tm safe_date;
- GMTIME_R(&safe_time, &safe_date);
+ struct tm * result;
+
+ /* reentr.h will automatically replace this with a call to gmtime_r()
+ * when appropriate */
+ result = gmtime(&safe_time);
+
+ assert(result != NULL);
+
+#if defined(HAS_GMTIME_R) && defined(USE_REENTRANT_API)
+
+ PERL_UNUSED_VAR(safe_date);
+#else
+ /* Here, no gmtime_r() and is a threaded perl where the result can be
+ * overwritten by a call in another thread. Copy to a safe place,
+ * hopefully before another gmtime can jump in and trash this
+ * result. */
+ memcpy(&safe_date, result, sizeof(safe_date));
+ result = &safe_date;
+#endif
- S_copy_little_tm_to_big_TM(&safe_date, p);
+ S_copy_little_tm_to_big_TM(result, p);
assert(S_check_tm(p));
return p;
diff --git a/time64.h b/time64.h
index 4da148b9aa..b86e771602 100644
--- a/time64.h
+++ b/time64.h
@@ -53,10 +53,4 @@ struct TM64 {
struct TM *Perl_gmtime64_r (const Time64_T *, struct TM *);
struct TM *Perl_localtime64_r (const Time64_T *, struct TM *);
-/* Not everyone has gmtime_r(), provide a replacement */
-#ifdef HAS_GMTIME_R
-# define GMTIME_R(clock, result) gmtime_r(clock, result)
-#else
-# define GMTIME_R(clock, result) S_gmtime_r(clock, result)
-#endif
#endif