aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Richard <[email protected]>2013-02-05 13:21:21 +0000
committerVincent Richard <[email protected]>2013-02-05 13:21:21 +0000
commitc2474f2b2b581ddfd207095b4ee433757e2abfbf (patch)
treeff7350316f0da2ba53ab50bd356187763aa8eda3
parentUpdated book. Added build target for HTML using HeVeA. (diff)
downloadvmime-c2474f2b2b581ddfd207095b4ee433757e2abfbf.tar.gz
vmime-c2474f2b2b581ddfd207095b4ee433757e2abfbf.zip
Check for localtime_r and gmtime_r at build instead of testing _REENTRANT. Use localtime_s and gmtime_s on Windows, if available.
-rw-r--r--CMakeLists.txt20
-rw-r--r--SConstruct4
-rw-r--r--cmake/config.hpp.cmake4
-rw-r--r--src/dateTime.cpp5
-rw-r--r--src/platforms/posix/posixHandler.cpp4
-rw-r--r--src/platforms/windows/windowsHandler.cpp10
6 files changed, 35 insertions, 12 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f044a2b..0b9e2218 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -16,6 +16,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
INCLUDE(cmake/Utils.cmake)
+INCLUDE(CheckFunctionExists)
+INCLUDE(CheckSymbolExists)
+INCLUDE(CheckTypeSize)
+
+
# CMake configuration
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin)
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib)
@@ -341,7 +346,6 @@ SET(
INCLUDE(cmake/TargetArch.cmake)
TARGET_ARCHITECTURE(CMAKE_TARGET_ARCHITECTURES)
-INCLUDE(CheckTypeSize)
CHECK_TYPE_SIZE(size_t VMIME_HAVE_SIZE_T)
@@ -453,8 +457,6 @@ ENDIF()
INCLUDE(FindGnuTLS)
INCLUDE(FindOpenSSL)
-
-INCLUDE(CheckFunctionExists)
SET(CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARY}")
CHECK_FUNCTION_EXISTS(gnutls_priority_set_direct VMIME_HAVE_GNUTLS_PRIORITY_FUNCS)
@@ -558,10 +560,16 @@ ENDIF()
##############################################################################
-# POSIX-specific checks
+# Platform-specific checks
-INCLUDE(CheckFunctionExists)
-INCLUDE(CheckSymbolExists)
+CHECK_FUNCTION_EXISTS(gmtime_s VMIME_HAVE_GMTIME_S)
+CHECK_FUNCTION_EXISTS(gmtime_r VMIME_HAVE_GMTIME_R)
+CHECK_FUNCTION_EXISTS(localtime_s VMIME_HAVE_LOCALTIME_S)
+CHECK_FUNCTION_EXISTS(localtime_r VMIME_HAVE_LOCALTIME_R)
+
+
+##############################################################################
+# POSIX-specific checks
CHECK_FUNCTION_EXISTS(getaddrinfo VMIME_HAVE_GETADDRINFO)
CHECK_FUNCTION_EXISTS(getnameinfo VMIME_HAVE_GETNAMEINFO)
diff --git a/SConstruct b/SConstruct
index 421d715f..cb974330 100644
--- a/SConstruct
+++ b/SConstruct
@@ -867,6 +867,10 @@ config_hpp.write("""
#define VMIME_HAVE_GETTID 0
#define VMIME_HAVE_SYSCALL 1
#define VMIME_HAVE_SYSCALL_GETTID 1
+#define VMIME_HAVE_LOCALTIME_R 1
+#define VMIME_HAVE_LOCALTIME_S 0
+#define VMIME_HAVE_GMTIME_R 1
+#define VMIME_HAVE_GMTIME_S 0
""")
config_hpp.write('\n')
diff --git a/cmake/config.hpp.cmake b/cmake/config.hpp.cmake
index 8e7f727d..3d9aba92 100644
--- a/cmake/config.hpp.cmake
+++ b/cmake/config.hpp.cmake
@@ -63,6 +63,10 @@ typedef unsigned @VMIME_32BIT_TYPE@ vmime_uint32;
#cmakedefine01 VMIME_HAVE_GETTID
#cmakedefine01 VMIME_HAVE_SYSCALL
#cmakedefine01 VMIME_HAVE_SYSCALL_GETTID
+#cmakedefine01 VMIME_HAVE_GMTIME_S
+#cmakedefine01 VMIME_HAVE_GMTIME_R
+#cmakedefine01 VMIME_HAVE_LOCALTIME_S
+#cmakedefine01 VMIME_HAVE_LOCALTIME_R
#define VMIME_SENDMAIL_PATH "@VMIME_SENDMAIL_PATH@"
diff --git a/src/dateTime.cpp b/src/dateTime.cpp
index feb18718..f98d7c64 100644
--- a/src/dateTime.cpp
+++ b/src/dateTime.cpp
@@ -23,6 +23,7 @@
#include <iomanip>
+#include "vmime/config.hpp"
#include "vmime/dateTime.hpp"
#include "vmime/platform.hpp"
#include "vmime/parserHelpers.hpp"
@@ -663,7 +664,7 @@ datetime::datetime(const time_t t, const int zone)
tms = *gtm;
else if (ltm)
tms = *ltm;
-#elif defined(_REENTRANT)
+#elif VMIME_HAVE_LOCALTIME_R
struct tm tms;
if (!gmtime_r(&t, &tms))
@@ -678,7 +679,7 @@ datetime::datetime(const time_t t, const int zone)
tms = *gtm;
else if (ltm)
tms = *ltm;
-#endif // _REENTRANT
+#endif
m_year = tms.tm_year + 1900;
m_month = tms.tm_mon + 1;
diff --git a/src/platforms/posix/posixHandler.cpp b/src/platforms/posix/posixHandler.cpp
index d90b316c..6536b5ef 100644
--- a/src/platforms/posix/posixHandler.cpp
+++ b/src/platforms/posix/posixHandler.cpp
@@ -132,7 +132,7 @@ const vmime::datetime posixHandler::getCurrentLocalTime() const
const time_t t(::time(NULL));
// Get the local time
-#ifdef _REENTRANT
+#if VMIME_HAVE_LOCALTIME_R
tm local;
::localtime_r(&t, &local);
#else
@@ -140,7 +140,7 @@ const vmime::datetime posixHandler::getCurrentLocalTime() const
#endif
// Get the UTC time
-#ifdef _REENTRANT
+#if VMIME_HAVE_GMTIME_R
tm gmt;
::gmtime_r(&t, &gmt);
#else
diff --git a/src/platforms/windows/windowsHandler.cpp b/src/platforms/windows/windowsHandler.cpp
index b1ab87fa..6583cab1 100644
--- a/src/platforms/windows/windowsHandler.cpp
+++ b/src/platforms/windows/windowsHandler.cpp
@@ -79,7 +79,10 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
const time_t t(::time(NULL));
// Get the local time
-#if defined(_REENTRANT) && defined(localtime_r)
+#if VMIME_HAVE_LOCALTIME_S
+ tm local;
+ ::localtime_s(&local, &t);
+#elif VMIME_HAVE_LOCALTIME_R
tm local;
::localtime_r(&t, &local);
#else
@@ -87,7 +90,10 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
#endif
// Get the UTC time
-#if defined(_REENTRANT) && defined(gmtime_r)
+#if VMIME_HAVE_GMTIME_S
+ tm gmt;
+ ::gmtime_s(&gmt, &t);
+#elif VMIME_HAVE_GMTIME_R
tm gmt;
::gmtime_r(&t, &gmt);
#else