From fbd92a913e1cf59593bfc18c6ca43081a86b9b41 Mon Sep 17 00:00:00 2001 From: Karl Heyes Date: Mon, 26 Jan 2004 21:49:07 +0000 Subject: [PATCH] add localtime_r checks, useful the threads svn path=/trunk/icecast/; revision=5785 --- configure.in | 2 +- src/util.c | 20 ++++++++++++++++++++ src/util.h | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/configure.in b/configure.in index bb5a709c..e68471a8 100644 --- a/configure.in +++ b/configure.in @@ -62,7 +62,7 @@ dnl Checks for typedefs, structures, and compiler characteristics. dnl Check for types dnl Checks for library functions. -AC_CHECK_FUNCS(nanosleep poll) +AC_CHECK_FUNCS(localtime_r nanosleep poll) XIPH_NET dnl -- configure options -- diff --git a/src/util.c b/src/util.c index 5c36fd72..9d586568 100644 --- a/src/util.c +++ b/src/util.c @@ -24,6 +24,7 @@ #endif #include "net/sock.h" +#include "thread/thread.h" #include "cfgfile.h" #include "util.h" @@ -587,3 +588,22 @@ char *util_dict_urlencode(util_dict *dict, char delim) return res; } +#ifndef HAVE_LOCALTIME_R +struct tm *localtime_r (const time_t *timep, struct tm *result) +{ + static mutex_t localtime_lock; + static int initialised = 0; + struct tm *tm; + + if (initialised == 0) + { + thread_mutex_create (&localtime_lock); + initialised = 1; + } + thread_mutex_lock (&localtime_lock); + tm = localtime (timep); + memcpy (result, tm, sizeof (*result)); + thread_mutex_unlock (&localtime_lock); + return result; +} +#endif diff --git a/src/util.h b/src/util.h index a41d6b92..820df714 100644 --- a/src/util.h +++ b/src/util.h @@ -32,4 +32,9 @@ void util_dict_free(util_dict *dict); int util_dict_set(util_dict *dict, const char *key, const char *val); const char *util_dict_get(util_dict *dict, const char *key); char *util_dict_urlencode(util_dict *dict, char delim); + +#ifndef HAVE_LOCALTIME_R +struct tm *localtime_r (const time_t *timep, struct tm *result); +#endif + #endif /* __UTIL_H__ */