mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-26 09:35:28 +00:00
Merge branch 'localtime_errors' into 'master'
Handle localtime errors See merge request OpenMW/openmw!2434
This commit is contained in:
commit
b58c658b56
@ -1,8 +1,15 @@
|
||||
#ifndef OPENMW_COMPONENTS_MISC_TIMECONVERT_H
|
||||
#define OPENMW_COMPONENTS_MISC_TIMECONVERT_H
|
||||
|
||||
#include <cerrno>
|
||||
#include <chrono>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
@ -22,9 +29,11 @@ namespace Misc
|
||||
{
|
||||
tm time_info{};
|
||||
#ifdef _WIN32
|
||||
(void)localtime_s(&time_info, &tp);
|
||||
if (const errno_t error = localtime_s(&time_info, &tp); error != 0)
|
||||
throw std::system_error(error, std::generic_category());
|
||||
#else
|
||||
(void)localtime_r(&tp, &time_info);
|
||||
if (localtime_r(&tp, &time_info) == nullptr)
|
||||
throw std::system_error(errno, std::generic_category());
|
||||
#endif
|
||||
std::stringstream out;
|
||||
out << std::put_time(&time_info, fmt);
|
||||
|
Loading…
x
Reference in New Issue
Block a user