mirror of https://github.com/Icinga/icinga2.git
Utility::FormatDateTime(): use localtime_s() on Windows
localtime() is not thread-safe as it returns a pointer to a shared tm struct. Everywhere except on Windows, localtime_r() is used already which avoids the problem by using a struct allocated by the caller for the output. Windows actually has a similar function called localtime_s() which has the same properties, just with a different name and order of arguments.
This commit is contained in:
parent
704acdc698
commit
c2c66908f6
|
@ -1058,15 +1058,12 @@ String Utility::FormatDateTime(const char *format, double ts)
|
|||
tm tmthen;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
tm *temp = localtime(&tempts);
|
||||
|
||||
if (!temp) {
|
||||
errno_t err = localtime_s(&tmthen, &tempts);
|
||||
if (err) {
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
<< boost::errinfo_api_function("localtime")
|
||||
<< boost::errinfo_errno(errno));
|
||||
<< boost::errinfo_api_function("localtime_s")
|
||||
<< boost::errinfo_errno(err));
|
||||
}
|
||||
|
||||
tmthen = *temp;
|
||||
#else /* _MSC_VER */
|
||||
if (!localtime_r(&tempts, &tmthen)) {
|
||||
BOOST_THROW_EXCEPTION(posix_error()
|
||||
|
|
Loading…
Reference in New Issue