summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-11-22 11:50:55 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-11-22 11:50:55 +0100
commitbaf99d32bc58074f10cf194e43963f47fae34c08 (patch)
treea4e80d11a641054db48c8cb2b075d43f3b399b67 /compat
parent2da189ce7435d44a83e37963e79ca0eb927f4e23 (diff)
a
Diffstat (limited to 'compat')
-rw-r--r--compat/strerror.cpp31
-rw-r--r--compat/strerror.hpp9
2 files changed, 40 insertions, 0 deletions
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 <errno.h>
+#include <string.h>
+
+namespace floormat {
+
+StringView get_error_string(ArrayView<char> buf)
+{
+#ifndef _WIN32
+ if constexpr(std::is_same_v<char*, std::decay_t<decltype(::strerror_r(errno, buf.data(), buf.size()))>>)
+ {
+ 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 <Corrade/Containers/ArrayView.h>
+#include <Corrade/Containers/StringView.h>
+
+namespace floormat {
+
+StringView get_error_string(ArrayView<char> buf);
+
+} // namespace floormat