diff options
| author | Mai <mai.iam2048@gmail.com> | 2024-02-18 17:12:29 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-18 17:12:29 -0500 |
| commit | 27415b0ba16035b89294a9ab948bac9e2f548987 (patch) | |
| tree | a08eb96ad1ee6b1e67fb8ed1908a89f691cc6f93 /Source/Core/Common/TimeUtil.cpp | |
| parent | cd9a7db4c19054305bb76cfb94864ba730446f2a (diff) | |
| parent | d3140e72c3f59f203c6c85049c5bcd25f9b14f3b (diff) | |
Merge pull request #12587 from AdmiralCurtiss/localtime
Core: Fix crash when inspecting a savestate with a timestamp that causes localtime() to error out
Diffstat (limited to 'Source/Core/Common/TimeUtil.cpp')
| -rw-r--r-- | Source/Core/Common/TimeUtil.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Source/Core/Common/TimeUtil.cpp b/Source/Core/Common/TimeUtil.cpp new file mode 100644 index 0000000000..39d989fb3f --- /dev/null +++ b/Source/Core/Common/TimeUtil.cpp @@ -0,0 +1,24 @@ +// Copyright 2024 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "Common/TimeUtil.h" + +#include <ctime> +#include <optional> + +namespace Common +{ +std::optional<std::tm> Localtime(std::time_t time) +{ + std::tm local_time; +#ifdef _MSC_VER + if (localtime_s(&local_time, &time) != 0) + return std::nullopt; +#else + std::tm* result = localtime_r(&time, &local_time); + if (result != &local_time) + return std::nullopt; +#endif + return local_time; +} +} // Namespace Common |
