summaryrefslogtreecommitdiff
path: root/time
diff options
context:
space:
mode:
authorbrane <brane@13f79535-47bb-0310-9956-ffa450edef68>2001-06-28 02:17:36 +0000
committerbrane <brane@13f79535-47bb-0310-9956-ffa450edef68>2001-06-28 02:17:36 +0000
commit15a3376c3e3988c6e1df4e7c08208060823751c6 (patch)
tree872157025383f84179db7eb4b517d2e7984d084a /time
parent12d6f279a32ca0471c63498c24f3a5f16eb5d3d2 (diff)
downloadlibapr-15a3376c3e3988c6e1df4e7c08208060823751c6.tar.gz
Cleaned up the code a bit and refactored common functionality.
(set_xt_gmtoff_from_tm): Check APR_HAS_THREADS and _POSIX_THREAD_SAFE_FUNCTIIONS, like elsewhere. (explode_time): New function. Contans most of the logic that was previowsly in tm_to_exp, apr_explode_time and apr_explode_localtime. (apr_explode_time and, apr_explode_localtime): Call explode_time. (tm_to_exp): Removed. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@61813 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'time')
-rw-r--r--time/unix/time.c66
1 files changed, 31 insertions, 35 deletions
diff --git a/time/unix/time.c b/time/unix/time.c
index b1e1fde44..94a394eba 100644
--- a/time/unix/time.c
+++ b/time/unix/time.c
@@ -95,7 +95,7 @@ static void set_xt_gmtoff_from_tm(apr_exploded_time_t *xt, struct tm *tm,
{
struct tm t;
int days = 0, hours = 0, minutes = 0;
-#ifdef HAVE_GMTIME_R
+#if APR_HAS_THREADS && defined (_POSIX_THREAD_SAFE_FUNCTIONS)
gmtime_r(tt, &t);
#else
t = *gmtime(tt);
@@ -109,35 +109,41 @@ static void set_xt_gmtoff_from_tm(apr_exploded_time_t *xt, struct tm *tm,
#endif
}
-static void tm_to_exp(apr_exploded_time_t *xt, struct tm *tm, time_t *tt)
+static void explode_time(apr_exploded_time_t *xt, apr_time_t t,
+ apr_int32_t offset, int use_localtime)
{
- xt->tm_sec = tm->tm_sec;
- xt->tm_min = tm->tm_min;
- xt->tm_hour = tm->tm_hour;
- xt->tm_mday = tm->tm_mday;
- xt->tm_mon = tm->tm_mon;
- xt->tm_year = tm->tm_year;
- xt->tm_wday = tm->tm_wday;
- xt->tm_yday = tm->tm_yday;
- xt->tm_isdst = tm->tm_isdst;
- set_xt_gmtoff_from_tm(xt,tm,tt);
+ struct tm tm;
+ time_t tt = (t / APR_USEC_PER_SEC) + offset;
+ xt->tm_usec = t % APR_USEC_PER_SEC;
+
+#if APR_HAS_THREADS && defined (_POSIX_THREAD_SAFE_FUNCTIONS)
+ if (use_localtime)
+ localtime_r(&tt, &tm);
+ else
+ gmtime_r(&tt, &tm);
+#else
+ if (use_localtime)
+ tm = *localtime(&tt);
+ else
+ tm = *gmtime(&tt);
+#endif
+
+ xt->tm_sec = tm.tm_sec;
+ xt->tm_min = tm.tm_min;
+ xt->tm_hour = tm.tm_hour;
+ xt->tm_mday = tm.tm_mday;
+ xt->tm_mon = tm.tm_mon;
+ xt->tm_year = tm.tm_year;
+ xt->tm_wday = tm.tm_wday;
+ xt->tm_yday = tm.tm_yday;
+ xt->tm_isdst = tm.tm_isdst;
+ set_xt_gmtoff_from_tm(xt,&tm,&tt);
}
apr_status_t apr_explode_time(apr_exploded_time_t *result, apr_time_t input,
apr_int32_t offs)
{
- time_t t = (input / APR_USEC_PER_SEC) + offs;
- result->tm_usec = input % APR_USEC_PER_SEC;
-
-#if APR_HAS_THREADS && defined (_POSIX_THREAD_SAFE_FUNCTIONS)
- {
- struct tm apple;
- gmtime_r(&t, &apple);
- tm_to_exp(result, &apple, &t);
- }
-#else
- tm_to_exp(result, gmtime(&t), &t);
-#endif
+ explode_time(result, input, offs, 0);
result->tm_gmtoff = offs;
return APR_SUCCESS;
}
@@ -153,17 +159,7 @@ apr_status_t apr_explode_localtime(apr_exploded_time_t *result, apr_time_t input
/* EMX gcc (OS/2) has a timezone global we can use */
return apr_explode_time(result, input, -timezone);
#else
- time_t mango = input / APR_USEC_PER_SEC;
-
-#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS)
- struct tm mangotm;
- localtime_r(&mango, &mangotm);
-#else /* !APR_HAS_THREADS */
- struct tm mangotm;
- mangotm = *localtime(&mango);
-#endif
- tm_to_exp(result, &mangotm, &mango);
- result->tm_usec = input % APR_USEC_PER_SEC;
+ explode_time(result, input, 0, 1);
return APR_SUCCESS;
#endif /* __EMX__ */
}