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:
parent
230a2c73ab
commit
c2474f2b2b
@ -16,6 +16,11 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.6 FATAL_ERROR)
|
|||||||
|
|
||||||
INCLUDE(cmake/Utils.cmake)
|
INCLUDE(cmake/Utils.cmake)
|
||||||
|
|
||||||
|
INCLUDE(CheckFunctionExists)
|
||||||
|
INCLUDE(CheckSymbolExists)
|
||||||
|
INCLUDE(CheckTypeSize)
|
||||||
|
|
||||||
|
|
||||||
# CMake configuration
|
# CMake configuration
|
||||||
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin)
|
SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY build/bin)
|
||||||
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib)
|
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY build/lib)
|
||||||
@ -341,7 +346,6 @@ SET(
|
|||||||
INCLUDE(cmake/TargetArch.cmake)
|
INCLUDE(cmake/TargetArch.cmake)
|
||||||
TARGET_ARCHITECTURE(CMAKE_TARGET_ARCHITECTURES)
|
TARGET_ARCHITECTURE(CMAKE_TARGET_ARCHITECTURES)
|
||||||
|
|
||||||
INCLUDE(CheckTypeSize)
|
|
||||||
CHECK_TYPE_SIZE(size_t VMIME_HAVE_SIZE_T)
|
CHECK_TYPE_SIZE(size_t VMIME_HAVE_SIZE_T)
|
||||||
|
|
||||||
|
|
||||||
@ -453,8 +457,6 @@ ENDIF()
|
|||||||
INCLUDE(FindGnuTLS)
|
INCLUDE(FindGnuTLS)
|
||||||
INCLUDE(FindOpenSSL)
|
INCLUDE(FindOpenSSL)
|
||||||
|
|
||||||
|
|
||||||
INCLUDE(CheckFunctionExists)
|
|
||||||
SET(CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARY}")
|
SET(CMAKE_REQUIRED_LIBRARIES "${GNUTLS_LIBRARY}")
|
||||||
CHECK_FUNCTION_EXISTS(gnutls_priority_set_direct VMIME_HAVE_GNUTLS_PRIORITY_FUNCS)
|
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)
|
CHECK_FUNCTION_EXISTS(gmtime_s VMIME_HAVE_GMTIME_S)
|
||||||
INCLUDE(CheckSymbolExists)
|
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(getaddrinfo VMIME_HAVE_GETADDRINFO)
|
||||||
CHECK_FUNCTION_EXISTS(getnameinfo VMIME_HAVE_GETNAMEINFO)
|
CHECK_FUNCTION_EXISTS(getnameinfo VMIME_HAVE_GETNAMEINFO)
|
||||||
|
@ -867,6 +867,10 @@ config_hpp.write("""
|
|||||||
#define VMIME_HAVE_GETTID 0
|
#define VMIME_HAVE_GETTID 0
|
||||||
#define VMIME_HAVE_SYSCALL 1
|
#define VMIME_HAVE_SYSCALL 1
|
||||||
#define VMIME_HAVE_SYSCALL_GETTID 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')
|
config_hpp.write('\n')
|
||||||
|
@ -63,6 +63,10 @@ typedef unsigned @VMIME_32BIT_TYPE@ vmime_uint32;
|
|||||||
#cmakedefine01 VMIME_HAVE_GETTID
|
#cmakedefine01 VMIME_HAVE_GETTID
|
||||||
#cmakedefine01 VMIME_HAVE_SYSCALL
|
#cmakedefine01 VMIME_HAVE_SYSCALL
|
||||||
#cmakedefine01 VMIME_HAVE_SYSCALL_GETTID
|
#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@"
|
#define VMIME_SENDMAIL_PATH "@VMIME_SENDMAIL_PATH@"
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
|
#include "vmime/config.hpp"
|
||||||
#include "vmime/dateTime.hpp"
|
#include "vmime/dateTime.hpp"
|
||||||
#include "vmime/platform.hpp"
|
#include "vmime/platform.hpp"
|
||||||
#include "vmime/parserHelpers.hpp"
|
#include "vmime/parserHelpers.hpp"
|
||||||
@ -663,7 +664,7 @@ datetime::datetime(const time_t t, const int zone)
|
|||||||
tms = *gtm;
|
tms = *gtm;
|
||||||
else if (ltm)
|
else if (ltm)
|
||||||
tms = *ltm;
|
tms = *ltm;
|
||||||
#elif defined(_REENTRANT)
|
#elif VMIME_HAVE_LOCALTIME_R
|
||||||
struct tm tms;
|
struct tm tms;
|
||||||
|
|
||||||
if (!gmtime_r(&t, &tms))
|
if (!gmtime_r(&t, &tms))
|
||||||
@ -678,7 +679,7 @@ datetime::datetime(const time_t t, const int zone)
|
|||||||
tms = *gtm;
|
tms = *gtm;
|
||||||
else if (ltm)
|
else if (ltm)
|
||||||
tms = *ltm;
|
tms = *ltm;
|
||||||
#endif // _REENTRANT
|
#endif
|
||||||
|
|
||||||
m_year = tms.tm_year + 1900;
|
m_year = tms.tm_year + 1900;
|
||||||
m_month = tms.tm_mon + 1;
|
m_month = tms.tm_mon + 1;
|
||||||
|
@ -132,7 +132,7 @@ const vmime::datetime posixHandler::getCurrentLocalTime() const
|
|||||||
const time_t t(::time(NULL));
|
const time_t t(::time(NULL));
|
||||||
|
|
||||||
// Get the local time
|
// Get the local time
|
||||||
#ifdef _REENTRANT
|
#if VMIME_HAVE_LOCALTIME_R
|
||||||
tm local;
|
tm local;
|
||||||
::localtime_r(&t, &local);
|
::localtime_r(&t, &local);
|
||||||
#else
|
#else
|
||||||
@ -140,7 +140,7 @@ const vmime::datetime posixHandler::getCurrentLocalTime() const
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Get the UTC time
|
// Get the UTC time
|
||||||
#ifdef _REENTRANT
|
#if VMIME_HAVE_GMTIME_R
|
||||||
tm gmt;
|
tm gmt;
|
||||||
::gmtime_r(&t, &gmt);
|
::gmtime_r(&t, &gmt);
|
||||||
#else
|
#else
|
||||||
|
@ -79,7 +79,10 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
|
|||||||
const time_t t(::time(NULL));
|
const time_t t(::time(NULL));
|
||||||
|
|
||||||
// Get the local time
|
// 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;
|
tm local;
|
||||||
::localtime_r(&t, &local);
|
::localtime_r(&t, &local);
|
||||||
#else
|
#else
|
||||||
@ -87,7 +90,10 @@ const vmime::datetime windowsHandler::getCurrentLocalTime() const
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Get the UTC time
|
// 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;
|
tm gmt;
|
||||||
::gmtime_r(&t, &gmt);
|
::gmtime_r(&t, &gmt);
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user