summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2023-11-25 04:10:04 +0100
committerStanislaw Halik <sthalik@misaki.pl>2023-11-25 04:10:04 +0100
commit01b770e5f171a440f01cb9a9b2d974e9c8c82690 (patch)
tree618eddef2d3ee1468733907ca0c36b383c47b669 /compat
parent2eec1c1e4c383c64cafe2e2f23fbc9aa1b96ccbf (diff)
a
Diffstat (limited to 'compat')
-rw-r--r--compat/prelude.hpp1
-rw-r--r--compat/strerror.cpp19
-rw-r--r--compat/strerror.hpp1
3 files changed, 14 insertions, 7 deletions
diff --git a/compat/prelude.hpp b/compat/prelude.hpp
index 79f54942..bb5c4da0 100644
--- a/compat/prelude.hpp
+++ b/compat/prelude.hpp
@@ -5,6 +5,7 @@
#include <Corrade/Utility/Macros.h>
#include <Magnum/Magnum.h>
+// todo add colors prefix thing
#define DBG_nospace (::Corrade::Utility::Debug{::Corrade::Utility::Debug::Flag::NoSpace})
#define WARN_nospace (::Corrade::Utility::Warning{::Corrade::Utility::Debug::Flag::NoSpace})
#define ERR_nospace (::Corrade::Utility::Error{::Corrade::Utility::Debug::Flag::NoSpace})
diff --git a/compat/strerror.cpp b/compat/strerror.cpp
index 303c78be..8b237153 100644
--- a/compat/strerror.cpp
+++ b/compat/strerror.cpp
@@ -1,26 +1,31 @@
#include "strerror.hpp"
-#include <errno.h>
+#include <cerrno>
#include <string.h>
namespace floormat {
-StringView get_error_string(ArrayView<char> buf)
+StringView get_error_string(ArrayView<char> buf, int error)
{
#ifdef _WIN32
- ::strerror_s(buf.data(), buf.size(), errno);
+ ::strerror_s(buf.data(), buf.size(), error);
if (buf[0])
- return buf;
+ return { buf.data() };
#elif defined __GLIBC__ && !((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
- char* str { ::strerror_r(errno, buf.data(), buf.size()) };
+ char* str { ::strerror_r(error, buf.data(), buf.size()) };
if (str)
return str;
#else
- int status { ::strerror_r(errno, buf.data(), buf.size()) };
+ int status { ::strerror_r(error, buf.data(), buf.size()) };
if (status == 0)
- return buf;
+ return { buf.data() };
#endif
return "Unknown error"_s;
};
+StringView get_error_string(ArrayView<char> buf)
+{
+ return get_error_string(buf, errno);
+}
+
} // namespace floormat
diff --git a/compat/strerror.hpp b/compat/strerror.hpp
index 1929d97d..8bb33ec7 100644
--- a/compat/strerror.hpp
+++ b/compat/strerror.hpp
@@ -4,6 +4,7 @@
namespace floormat {
+StringView get_error_string(ArrayView<char> buf, int error);
StringView get_error_string(ArrayView<char> buf);
} // namespace floormat