1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-03-23 19:20:56 +00:00

Handle localtime errors

This commit is contained in:
elsid 2022-09-25 14:53:19 +02:00
parent f7da42870e
commit dd63a1602f
No known key found for this signature in database
GPG Key ID: 4DE04C198CBA7625

View File

@ -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);