}
+/* Simulate localtime_r() to the best of our ability */
+struct tm * fake_localtime_r(const time_t *clock, struct tm *result) {
+ const struct tm *static_result = localtime(clock);
+
+ assert(result != NULL);
+
+ if( static_result == NULL ) {
+ memset(result, 0, sizeof(*result));
+ return NULL;
+ }
+ else {
+ memcpy(result, static_result, sizeof(*result));
+ return result;
+ }
+}
+
+
+/* Simulate gmtime_r() to the best of our ability */
+struct tm * fake_gmtime_r(const time_t *clock, struct tm *result) {
+ const struct tm *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;
+ }
+}
+
+
struct tm *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;
Time64_T time = *in_time;
Year year = 70;
+ assert(p != NULL);
+
/* Use the system gmtime() if time_t is small enough */
if( SHOULD_USE_SYSTEM_GMTIME(*in_time) ) {
time_t safe_time = *in_time;
- gmtime_r(&safe_time, p);
+ GMTIME_R(&safe_time, p);
assert(_check_tm(p));
return p;
}
Year orig_year;
int month_diff;
+ assert(local_tm != NULL);
+
/* Use the system localtime() if time_t is small enough */
if( SHOULD_USE_SYSTEM_LOCALTIME(*time) ) {
safe_time = *time;
- localtime_r(&safe_time, local_tm);
+ LOCALTIME_R(&safe_time, local_tm);
assert(_check_tm(local_tm));
return local_tm;
}
}
safe_time = TIMEGM(&gm_tm);
- if( localtime_r(&safe_time, local_tm) == NULL )
+ if( LOCALTIME_R(&safe_time, local_tm) == NULL )
return NULL;
local_tm->tm_year = orig_year;
/* Configuration. */
/* Define as appropriate for your system */
/*
+ HAS_GMTIME_R
+ Defined if your system has gmtime_r()
+
+ HAS_LOCALTIME_R
+ Defined if your system has localtime_r()
+
HAS_TIMEGM
Defined if your system has timegm()
struct tm *localtime64_r (const Time64_T *, struct tm *);
Time64_T timegm64 (struct tm *);
+
+/* Not everyone has gm/localtime_r() */
+#ifdef HAS_LOCALTIME_R
+# define LOCALTIME_R(clock, result) localtime_r(clock, result)
+#else
+# define LOCALTIME_R(clock, result) fake_localtime_r(clock, result)
+#endif
+#ifdef HAS_GMTIME_R
+# define GMTIME_R(clock, result) gmtime_r(clock, result)
+#else
+# define GMTIME_R(clock, result) fake_gmtime_r(clock, result)
+#endif
+
#endif
# endif
# endif
#endif /* HAS_GETSPNAM_R */
-#ifdef HAS_GMTIME_R
-#endif /* HAS_GMTIME_R */
-#ifdef HAS_LOCALTIME_R
-#endif /* HAS_LOCALTIME_R */
#ifdef HAS_RANDOM_R
#endif /* HAS_RANDOM_R */
#ifdef HAS_READDIR_R
# endif
Newx(PL_reentrant_buffer->_spent_buffer, PL_reentrant_buffer->_spent_size, char);
#endif /* HAS_GETSPNAM_R */
-#ifdef HAS_GMTIME_R
-#endif /* HAS_GMTIME_R */
-#ifdef HAS_LOCALTIME_R
-#endif /* HAS_LOCALTIME_R */
#ifdef HAS_RANDOM_R
#endif /* HAS_RANDOM_R */
#ifdef HAS_READDIR_R
#ifdef HAS_GETSPNAM_R
Safefree(PL_reentrant_buffer->_spent_buffer);
#endif /* HAS_GETSPNAM_R */
-#ifdef HAS_GMTIME_R
-#endif /* HAS_GMTIME_R */
-#ifdef HAS_LOCALTIME_R
-#endif /* HAS_LOCALTIME_R */
#ifdef HAS_RANDOM_R
#endif /* HAS_RANDOM_R */
#ifdef HAS_READDIR_R
#define REENTRANT_PROTO_S_SBIE 69
#define REENTRANT_PROTO_S_SBW 70
#define REENTRANT_PROTO_S_TISBI 71
-#define REENTRANT_PROTO_S_TS 72
-#define REENTRANT_PROTO_S_TSBI 73
-#define REENTRANT_PROTO_S_TSBIE 74
-#define REENTRANT_PROTO_S_TWISBIE 75
-#define REENTRANT_PROTO_V_D 76
-#define REENTRANT_PROTO_V_H 77
-#define REENTRANT_PROTO_V_ID 78
+#define REENTRANT_PROTO_S_TSBI 72
+#define REENTRANT_PROTO_S_TSBIE 73
+#define REENTRANT_PROTO_S_TWISBIE 74
+#define REENTRANT_PROTO_V_D 75
+#define REENTRANT_PROTO_V_H 76
+#define REENTRANT_PROTO_V_ID 77
/* Defines for indicating which special features are supported. */
FILE* _spent_fptr;
# endif
#endif /* HAS_GETSPNAM_R */
-#ifdef HAS_GMTIME_R
- struct tm _gmtime_struct;
-#endif /* HAS_GMTIME_R */
-#ifdef HAS_LOCALTIME_R
- struct tm _localtime_struct;
-#endif /* HAS_LOCALTIME_R */
#ifdef HAS_RANDOM_R
struct random_data _random_struct;
# if RANDOM_R_PROTO == REENTRANT_PROTO_I_iS
# endif /* HAS_GETSPNAM */
#endif /* HAS_GETSPNAM_R */
-#ifdef HAS_GMTIME_R
-# if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
-# undef gmtime
-# if !defined(gmtime) && GMTIME_R_PROTO == REENTRANT_PROTO_S_TS
-# define gmtime(a) (gmtime_r(a, &PL_reentrant_buffer->_gmtime_struct) ? &PL_reentrant_buffer->_gmtime_struct : 0)
-# endif /* if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1) */
-# if !defined(gmtime) && GMTIME_R_PROTO == REENTRANT_PROTO_I_TS
-# define gmtime(a) (gmtime_r(a, &PL_reentrant_buffer->_gmtime_struct) == 0 ? &PL_reentrant_buffer->_gmtime_struct : 0)
-# endif /* if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1) */
-# endif /* HAS_GMTIME */
-#endif /* HAS_GMTIME_R */
-
-#ifdef HAS_LOCALTIME_R
-# if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
-# undef localtime
-# if !defined(localtime) && LOCALTIME_R_PROTO == REENTRANT_PROTO_S_TS
-# define localtime(a) (L_R_TZSET localtime_r(a, &PL_reentrant_buffer->_localtime_struct) ? &PL_reentrant_buffer->_localtime_struct : 0)
-# endif /* if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1) */
-# if !defined(localtime) && LOCALTIME_R_PROTO == REENTRANT_PROTO_I_TS
-# define localtime(a) (L_R_TZSET localtime_r(a, &PL_reentrant_buffer->_localtime_struct) == 0 ? &PL_reentrant_buffer->_localtime_struct : 0)
-# endif /* if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1) */
-# endif /* HAS_LOCALTIME */
-#endif /* HAS_LOCALTIME_R */
-
#ifdef HAS_RANDOM_R
# if defined(PERL_REENTR_API) && (PERL_REENTR_API+0 == 1)
# undef random
EOF
pushssif $endif;
}
- elsif ($func =~ /^(drand48|gmtime|localtime|random|srandom)$/) {
+ elsif ($func =~ /^(drand48|random|srandom)$/) {
pushssif $ifdef;
push @struct, <<EOF;
$seent{$func} _${func}_struct;
}
my $call = "${func}_r($v$w)";
- if ($func eq 'localtime') {
- $call = "L_R_TZSET $call";
- }
# Must make OpenBSD happy
my $memzero = '';
getservbyport IC|netdb |struct servent |I_ICSBWR|S_ICSBI|I_ICSD|D=struct servent_data*
getservent |netdb |struct servent |I_SBWR|I_SBI|S_SBI|I_SD|D=struct servent_data*
getspnam C |shadow |struct spwd |I_CSBWR|S_CSBI
-gmtime T |time |struct tm |S_TS|I_TS|T=const time_t*
-localtime T |time |struct tm |S_TS|I_TS|T=const time_t*
random |stdlib |struct random_data|I_iS|I_lS|I_St|i=int*|l=long*|t=int32_t*
readdir T |dirent |struct dirent |I_TSR|I_TS|T=DIR*
readdir64 T |dirent |struct dirent64|I_TSR|I_TS|T=DIR*