From baf99d32bc58074f10cf194e43963f47fae34c08 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 22 Nov 2023 11:50:55 +0100 Subject: a --- compat/strerror.cpp | 31 +++++++++++++++++++++++++++++++ compat/strerror.hpp | 9 +++++++++ 2 files changed, 40 insertions(+) create mode 100644 compat/strerror.cpp create mode 100644 compat/strerror.hpp (limited to 'compat') diff --git a/compat/strerror.cpp b/compat/strerror.cpp new file mode 100644 index 00000000..67b87e2f --- /dev/null +++ b/compat/strerror.cpp @@ -0,0 +1,31 @@ +#include "strerror.hpp" +#include +#include + +namespace floormat { + +StringView get_error_string(ArrayView buf) +{ +#ifndef _WIN32 + if constexpr(std::is_same_v>) + { + const char* str { ::strerror_r(errno, buf.data(), buf.size()) }; + if (str) + return str; + } + else + { + const int status { ::strerror_r(errno, buf.data(), buf.size()) }; + if (status == 0) + return buf; + } +#else + ::strerror_s(buf.data(), buf.size(), errno); + if (buf[0]) + return buf; +#endif + + return "Unknown error"_s; +}; + +} // namespace floormat diff --git a/compat/strerror.hpp b/compat/strerror.hpp new file mode 100644 index 00000000..1929d97d --- /dev/null +++ b/compat/strerror.hpp @@ -0,0 +1,9 @@ +#pragma once +#include +#include + +namespace floormat { + +StringView get_error_string(ArrayView buf); + +} // namespace floormat -- cgit v1.2.3