From 01b770e5f171a440f01cb9a9b2d974e9c8c82690 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Nov 2023 04:10:04 +0100 Subject: a --- compat/prelude.hpp | 1 + compat/strerror.cpp | 19 ++++++++++++------- compat/strerror.hpp | 1 + 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'compat') 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 #include +// 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 +#include #include namespace floormat { -StringView get_error_string(ArrayView buf) +StringView get_error_string(ArrayView 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 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 buf, int error); StringView get_error_string(ArrayView buf); } // namespace floormat -- cgit v1.2.3