check for localtime_r() and gmtime_r() functions during configuration

Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
Ivailo Monev 2020-01-07 17:40:17 +00:00
parent 196cc93bed
commit 8a014987a6
3 changed files with 21 additions and 32 deletions

View file

@ -220,13 +220,13 @@ check_include_file(sys/time.h HAVE_SYS_TIME_H)
check_type_size(size_t QT_POINTER_SIZE) check_type_size(size_t QT_POINTER_SIZE)
# POSIX.1-2001 # POSIX.1-2001
katie_optional_function(getpwuid_r "pwd.h") katie_check_function(getpwuid_r "pwd.h")
katie_optional_function(getgrgid_r "grp.h") katie_check_function(getgrgid_r "grp.h")
# XSI POSIX.1-2001 functions # XSI POSIX.1-2001 functions
katie_optional_function(strerror_r "string.h") katie_check_function(strerror_r "string.h")
# POSIX.1-2008 functions # SUSv2
katie_require_function(realpath "stdlib.h") katie_check_function(localtime_r "time.h")
katie_require_function(unsetenv "stdlib.h") katie_check_function(gmtime_r "time.h")
if(KATIE_COMPILER MATCHES "(gcc|clang)") if(KATIE_COMPILER MATCHES "(gcc|clang)")
set(QT_VISIBILITY_AVAILABLE TRUE) set(QT_VISIBILITY_AVAILABLE TRUE)

View file

@ -17,10 +17,10 @@ macro(KATIE_WARNING MESSAGESTR)
endmacro() endmacro()
# a macro to check for function presence in header, if function is found a # a macro to check for function presence in header, if function is found a
# definition is added. noteee that check_symbol_exists() and # definition is added. note that check_symbol_exists() and
# check_function_exists() cache the result variables so they can be used # check_function_exists() cache the result variables so they can be used
# anywhere # anywhere
macro(KATIE_OPTIONAL_FUNCTION FORFUNCTION FROMHEADER) macro(KATIE_CHECK_FUNCTION FORFUNCTION FROMHEADER)
check_symbol_exists("${FORFUNCTION}" "${FROMHEADER}" HAVE_${FORFUNCTION}) check_symbol_exists("${FORFUNCTION}" "${FROMHEADER}" HAVE_${FORFUNCTION})
if(NOT HAVE_${FORFUNCTION}) if(NOT HAVE_${FORFUNCTION})
check_function_exists("${FORFUNCTION}" HAVE_${FORFUNCTION}) check_function_exists("${FORFUNCTION}" HAVE_${FORFUNCTION})
@ -31,17 +31,6 @@ macro(KATIE_OPTIONAL_FUNCTION FORFUNCTION FROMHEADER)
endif() endif()
endmacro() endmacro()
# same as katie_optional_function(), however if not found an error is send
macro(KATIE_REQUIRE_FUNCTION FORFUNCTION FROMHEADER)
check_symbol_exists("${FORFUNCTION}" "${FROMHEADER}" HAVE_${FORFUNCTION})
if(NOT HAVE_${FORFUNCTION})
check_function_exists("${FORFUNCTION}" HAVE_${FORFUNCTION})
endif()
if(NOT HAVE_${FORFUNCTION})
message(SEND_ERROR "katie_require_function(${FORFUNCTION}, ${FROMHEADER}) failed")
endif()
endmacro()
# a macro to write data to file, does nothing if the file exists and its # a macro to write data to file, does nothing if the file exists and its
# content is the same as the data # content is the same as the data
macro(KATIE_WRITE_FILE OUTFILE DATA) macro(KATIE_WRITE_FILE OUTFILE DATA)

View file

@ -2781,14 +2781,14 @@ QDate QDate::currentDate()
time_t ltime; time_t ltime;
time(&ltime); time(&ltime);
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) #if !defined(QT_NO_THREAD) && defined(QT_HAVE_LOCALTIME_R)
// use the reentrant version of localtime() where available // use the reentrant version of localtime() where available
tzset(); tzset();
struct tm res; struct tm res;
struct tm *t = localtime_r(&ltime, &res); struct tm *t = localtime_r(&ltime, &res);
#else #else
struct tm *t = localtime(&ltime); struct tm *t = localtime(&ltime);
#endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS #endif // !QT_NO_THREAD && QT_HAVE_LOCALTIME_R
d.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday); d.jd = julianDayFromDate(t->tm_year + 1900, t->tm_mon + 1, t->tm_mday);
return d; return d;
@ -2802,14 +2802,14 @@ QTime QTime::currentTime()
gettimeofday(&tv, Q_NULLPTR); gettimeofday(&tv, Q_NULLPTR);
time_t ltime = tv.tv_sec; time_t ltime = tv.tv_sec;
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) #if !defined(QT_NO_THREAD) && defined(QT_HAVE_LOCALTIME_R)
// use the reentrant version of localtime() where available // use the reentrant version of localtime() where available
tzset(); tzset();
struct tm res; struct tm res;
struct tm *t = localtime_r(&ltime, &res); struct tm *t = localtime_r(&ltime, &res);
#else #else
struct tm *t = localtime(&ltime); struct tm *t = localtime(&ltime);
#endif #endif // !QT_NO_THREAD && QT_HAVE_LOCALTIME_R
Q_CHECK_PTR(t); Q_CHECK_PTR(t);
ct.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000); ct.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000);
@ -2824,14 +2824,14 @@ QDateTime QDateTime::currentDateTime()
gettimeofday(&tv, Q_NULLPTR); gettimeofday(&tv, Q_NULLPTR);
time_t ltime = tv.tv_sec; time_t ltime = tv.tv_sec;
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) #if !defined(QT_NO_THREAD) && defined(localtime_r)
// use the reentrant version of localtime() where available // use the reentrant version of localtime() where available
tzset(); tzset();
struct tm res; struct tm res;
struct tm *t = localtime_r(&ltime, &res); struct tm *t = localtime_r(&ltime, &res);
#else #else
struct tm *t = localtime(&ltime); struct tm *t = localtime(&ltime);
#endif #endif // !QT_NO_THREAD && QT_HAVE_LOCALTIME_R
QDateTime dt; QDateTime dt;
dt.d->time.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000); dt.d->time.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000);
@ -2851,13 +2851,13 @@ QDateTime QDateTime::currentDateTimeUtc()
gettimeofday(&tv, Q_NULLPTR); gettimeofday(&tv, Q_NULLPTR);
time_t ltime = tv.tv_sec; time_t ltime = tv.tv_sec;
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) #if !defined(QT_NO_THREAD) && defined(QT_HAVE_GMTIME_R)
// use the reentrant version of localtime() where available // use the reentrant version of gmtime_r() where available
struct tm res; struct tm res;
struct tm *t = gmtime_r(&ltime, &res); struct tm *t = gmtime_r(&ltime, &res);
#else #else
struct tm *t = gmtime(&ltime); struct tm *t = gmtime(&ltime);
#endif #endif // !QT_NO_THREAD && QT_HAVE_GMTIME_R
QDateTime dt; QDateTime dt;
dt.d->time.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000); dt.d->time.mds = msecsFromDecomposed(t->tm_hour, t->tm_min, t->tm_sec, tv.tv_usec / 1000);
@ -3484,14 +3484,14 @@ static QDateTimePrivate::Spec utcToLocal(QDate &date, QTime &time)
// won't overflow because of fakeDate // won't overflow because of fakeDate
time_t secsSince1Jan1970UTC = toMSecsSinceEpoch_helper(fakeDate.toJulianDay(), QTime().msecsTo(time)) / 1000; time_t secsSince1Jan1970UTC = toMSecsSinceEpoch_helper(fakeDate.toJulianDay(), QTime().msecsTo(time)) / 1000;
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) #if !defined(QT_NO_THREAD) && defined(QT_HAVE_LOCALTIME_R)
// use the reentrant version of localtime() where available // use the reentrant version of localtime() where available
tzset(); tzset();
tm res; tm res;
tm *brokenDown = localtime_r(&secsSince1Jan1970UTC, &res); tm *brokenDown = localtime_r(&secsSince1Jan1970UTC, &res);
#else #else
tm *brokenDown = localtime(&secsSince1Jan1970UTC); tm *brokenDown = localtime(&secsSince1Jan1970UTC);
#endif #endif // !QT_NO_THREAD && QT_HAVE_LOCALTIME_R
if (!brokenDown) { if (!brokenDown) {
date = QDate(1970, 1, 1); date = QDate(1970, 1, 1);
time = QTime(); time = QTime();
@ -3526,13 +3526,13 @@ static void localToUtc(QDate &date, QTime &time, int isdst)
localTM.tm_year = fakeDate.year() - 1900; localTM.tm_year = fakeDate.year() - 1900;
localTM.tm_isdst = isdst; localTM.tm_isdst = isdst;
time_t secsSince1Jan1970UTC = mktime(&localTM); time_t secsSince1Jan1970UTC = mktime(&localTM);
#if !defined(QT_NO_THREAD) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) #if !defined(QT_NO_THREAD) && defined(QT_HAVE_GMTIME_R)
// use the reentrant version of gmtime() where available // use the reentrant version of gmtime() where available
tm res; tm res;
tm *brokenDown = gmtime_r(&secsSince1Jan1970UTC, &res); tm *brokenDown = gmtime_r(&secsSince1Jan1970UTC, &res);
#else #else
tm *brokenDown = gmtime(&secsSince1Jan1970UTC); tm *brokenDown = gmtime(&secsSince1Jan1970UTC);
#endif // !QT_NO_THREAD && _POSIX_THREAD_SAFE_FUNCTIONS #endif // !QT_NO_THREAD && QT_HAVE_GMTIME_R
if (!brokenDown) { if (!brokenDown) {
date = QDate(1970, 1, 1); date = QDate(1970, 1, 1);
time = QTime(); time = QTime();