From 70c3580f81dd560072209fe32c740c33d3781c67 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 22 Feb 2005 07:03:03 +0000 Subject: Patch to localtime/gmtime handling: use the _r variants where available. Use mutexes to fake _r where necessary. Make mutexes no-ops where no threading is enabled. svn:r3653 --- src/common/util.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'src/common/util.c') diff --git a/src/common/util.c b/src/common/util.c index 11c592ca96..2d7f6903f7 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -603,15 +603,17 @@ static const char *MONTH_NAMES[] = "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; void format_rfc1123_time(char *buf, time_t t) { - struct tm *tm = gmtime(&t); + struct tm tm; - strftime(buf, RFC1123_TIME_LEN+1, "___, %d ___ %Y %H:%M:%S GMT", tm); - tor_assert(tm->tm_wday >= 0); - tor_assert(tm->tm_wday <= 6); - memcpy(buf, WEEKDAY_NAMES[tm->tm_wday], 3); - tor_assert(tm->tm_wday >= 0); - tor_assert(tm->tm_mon <= 11); - memcpy(buf+8, MONTH_NAMES[tm->tm_mon], 3); + tor_gmtime_r(&t, &tm); + + strftime(buf, RFC1123_TIME_LEN+1, "___, %d ___ %Y %H:%M:%S GMT", &tm); + tor_assert(tm.tm_wday >= 0); + tor_assert(tm.tm_wday <= 6); + memcpy(buf, WEEKDAY_NAMES[tm.tm_wday], 3); + tor_assert(tm.tm_wday >= 0); + tor_assert(tm.tm_mon <= 11); + memcpy(buf+8, MONTH_NAMES[tm.tm_mon], 3); } int parse_rfc1123_time(const char *buf, time_t *t) { @@ -649,11 +651,13 @@ int parse_rfc1123_time(const char *buf, time_t *t) { } void format_local_iso_time(char *buf, time_t t) { - strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", localtime(&t)); + struct tm tm; + strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_localtime_r(&t, &tm)); } void format_iso_time(char *buf, time_t t) { - strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", gmtime(&t)); + struct tm tm; + strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm)); } int parse_iso_time(const char *cp, time_t *t) { -- cgit v1.2.3-54-g00ecf