aboutsummaryrefslogtreecommitdiff
path: root/src/common/compat.c
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2005-02-22 07:03:03 +0000
committerNick Mathewson <nickm@torproject.org>2005-02-22 07:03:03 +0000
commit70c3580f81dd560072209fe32c740c33d3781c67 (patch)
treea914e5d669ef9bf6d7b3ed79a07157cd676c9c61 /src/common/compat.c
parentd01718841e5bc3d365191e74bebbccee48c8b045 (diff)
downloadtor-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/compat.c')
-rw-r--r--src/common/compat.c39
1 files changed, 34 insertions, 5 deletions
diff --git a/src/common/compat.c b/src/common/compat.c
index 5de2081ca5..d7ed324b49 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -753,6 +753,40 @@ void tor_gettimeofday(struct timeval *timeval) {
return;
}
+#ifndef HAVE_LOCALTIME_R
+struct tm *tor_localtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+#ifdef TOR_IS_MULTITHREADED
+ static tor_mutex_t *m=NULL;
+ if (!m) { m=tor_mutex_new(); }
+#endif
+ tor_assert(result);
+ tor_mutex_acquire(m);
+ r = localtime(timep);
+ memcpy(result, r, sizeof(struct tm));
+ tor_mutex_release(m);
+ return result;
+}
+#endif
+
+#ifndef HAVE_GMTIME_R
+struct tm *tor_gmtime_r(const time_t *timep, struct tm *result)
+{
+ struct tm *r;
+#ifdef TOR_IS_MULTITHREADED
+ static tor_mutex_t *m=NULL;
+ if (!m) { m=tor_mutex_new(); }
+#endif
+ tor_assert(result);
+ tor_mutex_acquire(m);
+ r = gmtime(timep);
+ memcpy(result, r, sizeof(struct tm));
+ tor_mutex_release(m);
+ return result;
+}
+#endif
+
#ifdef USE_WIN32_THREADS
struct tor_mutex_t {
HANDLE handle;
@@ -833,11 +867,6 @@ tor_get_thread_id(void)
struct tor_mutex_t {
int _unused;
};
-tor_mutex_t *tor_mutex_new(void) { return NULL; }
-void tor_mutex_acquire(tor_mutex_t *m) { }
-void tor_mutex_release(tor_mutex_t *m) { }
-void tor_mutex_free(tor_mutex_t *m) { }
-unsigned long tor_get_thread_id(void) { return 1; }
#endif
/**