diff options
author | Nick Mathewson <nickm@torproject.org> | 2005-02-22 07:03:03 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2005-02-22 07:03:03 +0000 |
commit | 70c3580f81dd560072209fe32c740c33d3781c67 (patch) | |
tree | a914e5d669ef9bf6d7b3ed79a07157cd676c9c61 /src/common/util.c | |
parent | d01718841e5bc3d365191e74bebbccee48c8b045 (diff) | |
download | tor-70c3580f81dd560072209fe32c740c33d3781c67.tar.gz tor-70c3580f81dd560072209fe32c740c33d3781c67.zip |
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
Diffstat (limited to 'src/common/util.c')
-rw-r--r-- | src/common/util.c | 24 |
1 files changed, 14 insertions, 10 deletions
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) { |