Bug #1030
- Added portable implementation of timegm for non GNU/BSD platforms that don't have their own implementation - Removed the use of tm_gmtoff on non GNU/BSD platforms that don't have it as part of the tm struct in time.h - Added CMake tests HAVE_TIMEGM and HAVE_TM_GMTOFF
This commit is contained in:
@@ -37,6 +37,7 @@
|
||||
#ifdef NIBBLER_FEATURE_REGEX
|
||||
#include <RX.h>
|
||||
#endif
|
||||
#include <cmake.h>
|
||||
|
||||
static const char* _uuid_pattern = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx";
|
||||
static const unsigned int _uuid_min_length = 9;
|
||||
@@ -701,7 +702,9 @@ bool Nibbler::getDateISO (time_t& t)
|
||||
tms.tm_hour = hour;
|
||||
tms.tm_min = minute;
|
||||
tms.tm_sec = second;
|
||||
#ifdef HAVE_TM_GMTOFF
|
||||
tms.tm_gmtoff = 0;
|
||||
#endif
|
||||
|
||||
t = timegm (&tms);
|
||||
return true;
|
||||
|
||||
20
src/util.cpp
20
src/util.cpp
@@ -610,3 +610,23 @@ const std::string indentProject (
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#ifndef HAVE_TIMEGM
|
||||
time_t timegm (struct tm *tm)
|
||||
{
|
||||
time_t ret;
|
||||
char *tz;
|
||||
tz = getenv ("TZ");
|
||||
setenv ("TZ", "UTC", 1);
|
||||
tzset ();
|
||||
ret = mktime (tm);
|
||||
if (tz)
|
||||
setenv ("TZ", tz, 1);
|
||||
else
|
||||
unsetenv ("TZ");
|
||||
tzset ();
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
@@ -84,5 +84,9 @@ const std::string indentProject (
|
||||
const std::string& whitespace = " ",
|
||||
char delimiter = '.');
|
||||
|
||||
#ifndef HAVE_TIMEGM
|
||||
time_t timegm (struct tm *tm);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Reference in New Issue
Block a user