summaryrefslogtreecommitdiff
path: root/time64.c
diff options
context:
space:
mode:
Diffstat (limited to 'time64.c')
-rw-r--r--time64.c45
1 files changed, 21 insertions, 24 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;