Check for localtime_r and gmtime_r at build instead of testing _REENTRANT. Use localtime_s and gmtime_s on Windows, if available.

This commit is contained in:
Vincent Richard 2013-02-05 14:21:21 +01:00
parent 230a2c73ab
commit c2474f2b2b
6 changed files with 35 additions and 12 deletions

View File

@ -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)

View File

@ -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')

View File

@ -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@"

View File

@ -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;

View File

@ -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

View File

@ -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