summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-18 19:06:33 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-18 19:06:33 +0000
commit4eb908d21a64bf147f4e5a891a7f10cf963c46b6 (patch)
tree9359feed203d08e4f13f05503f72bb0655db02db /time.c
parent9a8b21446ea9edf55272d5e048d97f1c94640e9e (diff)
* time.c (LOCALTIME): organize #ifdefs.
* time.c (GMTIME): define only ifndef HAVE_STRUCT_TM_TM_GMTOFF. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54187 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r--time.c58
1 files changed, 22 insertions, 36 deletions
diff --git a/time.c b/time.c
index b65d6e5c85..80eacf07f1 100644
--- a/time.c
+++ b/time.c
@@ -783,45 +783,29 @@ static struct vtm *localtimew(wideval_t timew, struct vtm *result);
static int leap_year_p(long y);
#define leap_year_v_p(y) leap_year_p(NUM2LONG(mod((y), INT2FIX(400))))
-#ifdef HAVE_GMTIME_R
-#define rb_gmtime_r(t, tm) gmtime_r((t), (tm))
-#define rb_localtime_r(t, tm) localtime_r((t), (tm))
-#else
-static inline struct tm *
-rb_gmtime_r(const time_t *tp, struct tm *result)
-{
- struct tm *t = gmtime(tp);
- if (t) *result = *t;
- return t;
-}
-
-static inline struct tm *
-rb_localtime_r(const time_t *tp, struct tm *result)
-{
- struct tm *t = localtime(tp);
- if (t) *result = *t;
- return t;
-}
-#endif
-
static struct tm *
-rb_localtime_r2(const time_t *t, struct tm *result)
+rb_localtime_r(const time_t *t, struct tm *result)
{
#if defined __APPLE__ && defined __LP64__
if (*t != (time_t)(int)*t) return NULL;
#endif
- result = rb_localtime_r(t, result);
+#ifdef HAVE_GMTIME_R
+ result = localtime_r(t, result);
+#else
+ {
+ struct tm *tmp = localtime(t);
+ if (tmp) *result = *tmp;
+ }
+#endif
#if defined(HAVE_MKTIME) && defined(LOCALTIME_OVERFLOW_PROBLEM)
if (result) {
long gmtoff1 = 0;
long gmtoff2 = 0;
struct tm tmp = *result;
time_t t2;
-# if defined(HAVE_STRUCT_TM_TM_GMTOFF)
- gmtoff1 = result->tm_gmtoff;
-# endif
t2 = mktime(&tmp);
# if defined(HAVE_STRUCT_TM_TM_GMTOFF)
+ gmtoff1 = result->tm_gmtoff;
gmtoff2 = tmp.tm_gmtoff;
# endif
if (*t + gmtoff1 != t2 + gmtoff2)
@@ -830,24 +814,26 @@ rb_localtime_r2(const time_t *t, struct tm *result)
#endif
return result;
}
-#define LOCALTIME(tm, result) (tzset(),rb_localtime_r2((tm), &(result)))
+#define LOCALTIME(tm, result) (tzset(),rb_localtime_r((tm), &(result)))
-#if !defined(HAVE_STRUCT_TM_TM_GMTOFF)
+#ifndef HAVE_STRUCT_TM_TM_GMTOFF
static struct tm *
-rb_gmtime_r2(const time_t *t, struct tm *result)
+rb_gmtime_r(const time_t *t, struct tm *result)
{
- result = rb_gmtime_r(t, result);
+#ifdef HAVE_GMTIME_R
+ result = gmtime_r(t, result);
+#else
+ struct tm *tmp = gmtime(t);
+ if (tmp) *result = *tmp;
+#endif
#if defined(HAVE_TIMEGM) && defined(LOCALTIME_OVERFLOW_PROBLEM)
- if (result) {
- struct tm tmp = *result;
- time_t t2 = timegm(&tmp);
- if (*t != t2)
- result = NULL;
+ if (result && *t != timegm(result)) {
+ return NULL;
}
#endif
return result;
}
-# define GMTIME(tm, result) rb_gmtime_r2((tm), &(result))
+# define GMTIME(tm, result) rb_gmtime_r((tm), &(result))
#endif
static const int common_year_yday_offset[] = {