}
+#ifdef DEBUGGING
static int check_tm(struct TM *tm)
{
/* Don't forget leap seconds */
return 1;
}
+#endif
/* The exceptional centuries without leap years cause the cycle to
}
-void copy_tm_to_TM(const struct tm *src, struct TM *dest) {
+void copy_little_tm_to_big_TM(const struct tm *src, struct TM *dest) {
if( src == NULL ) {
memset(dest, 0, sizeof(*dest));
}
}
-void copy_TM_to_tm(const struct TM *src, struct tm *dest) {
+void copy_big_TM_to_little_tm(const struct TM *src, struct tm *dest) {
if( src == NULL ) {
memset(dest, 0, sizeof(*dest));
}
/* Simulate localtime_r() to the best of our ability */
struct tm * fake_localtime_r(const time_t *clock, struct tm *result) {
+ dTHX; /* in case the following is defined as Perl_my_localtime(aTHX_ ...) */
const struct tm *static_result = localtime(clock);
assert(result != NULL);
/* Simulate gmtime_r() to the best of our ability */
struct tm * fake_gmtime_r(const time_t *clock, struct tm *result) {
+ dTHX; /* in case the following is defined as Perl_my_gmtime(aTHX_ ...) */
const struct tm *static_result = gmtime(clock);
assert(result != NULL);
/* Use the system gmtime() if time_t is small enough */
if( SHOULD_USE_SYSTEM_GMTIME(*in_time) ) {
- time_t safe_time = *in_time;
+ time_t safe_time = (time_t)*in_time;
struct tm safe_date;
GMTIME_R(&safe_time, &safe_date);
- copy_tm_to_TM(&safe_date, p);
+ copy_little_tm_to_big_TM(&safe_date, p);
assert(check_tm(p));
return p;
/* Use the system localtime() if time_t is small enough */
if( SHOULD_USE_SYSTEM_LOCALTIME(*time) ) {
- safe_time = *time;
+ safe_time = (time_t)*time;
TRACE1("Using system localtime for %lld\n", *time);
LOCALTIME_R(&safe_time, &safe_date);
- copy_tm_to_TM(&safe_date, local_tm);
+ copy_little_tm_to_big_TM(&safe_date, local_tm);
assert(check_tm(local_tm));
return local_tm;
gm_tm.tm_year = safe_year((Year)(gm_tm.tm_year + 1900)) - 1900;
}
- safe_time = timegm64(&gm_tm);
+ safe_time = (time_t)timegm64(&gm_tm);
if( LOCALTIME_R(&safe_time, &safe_date) == NULL ) {
TRACE1("localtime_r(%d) returned NULL\n", (int)safe_time);
return NULL;
}
- copy_tm_to_TM(&safe_date, local_tm);
+ copy_little_tm_to_big_TM(&safe_date, local_tm);
local_tm->tm_year = orig_year;
if( local_tm->tm_year != orig_year ) {