From 01b770e5f171a440f01cb9a9b2d974e9c8c82690 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 25 Nov 2023 04:10:04 +0100 Subject: a --- compat/strerror.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'compat/strerror.cpp') 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 -- cgit v1.2.3