Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MSVC]: Use reentrant function in localtime and gmtime. #226

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions include/boost/date_time/c_time.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ namespace date_time {
result = 0;
else
*result = tmp;
#elif defined(_MSC_VER)
std::tm tmp;
if(localtime_s(&tmp, t))
result = 0;
else
*result = tmp;
#else
result = localtime_r(t, result);
#endif
Expand All @@ -81,6 +87,12 @@ namespace date_time {
result = 0;
else
*result = tmp;
#elif defined(_MSC_VER)
std::tm tmp;
if(gmtime_s(&tmp, t))
result = 0;
else
*result = tmp;
#else
result = gmtime_r(t, result);
#endif
Expand All @@ -93,9 +105,6 @@ namespace date_time {
#if defined(__clang__) // Clang has to be checked before MSVC
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400))
#pragma warning(push) // preserve warning settings
#pragma warning(disable : 4996) // disable depricated localtime/gmtime warning on vc8
#endif
//! requires a pointer to a user created std::tm struct
inline
Expand All @@ -117,8 +126,6 @@ namespace date_time {
}
#if defined(__clang__) // Clang has to be checked before MSVC
#pragma clang diagnostic pop
#elif (defined(_MSC_VER) && (_MSC_VER >= 1400))
#pragma warning(pop) // restore warnings to previous state
#endif

#endif // BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS
Expand Down
2 changes: 1 addition & 1 deletion include/boost/date_time/compiler_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ namespace std {


#if defined(BOOST_HAS_THREADS)
# if defined(_MSC_VER) || defined(__MWERKS__) || defined(__MINGW32__) || defined(__BORLANDC__)
# if defined(__MWERKS__) || defined(__MINGW32__) || defined(__BORLANDC__)
//no reentrant posix functions (eg: localtime_r)
# elif (!defined(__hpux) || (defined(__hpux) && defined(_REENTRANT)))
# define BOOST_DATE_TIME_HAS_REENTRANT_STD_FUNCTIONS
Expand Down