diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-25 04:10:04 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-25 04:10:04 +0100 |
| commit | 01b770e5f171a440f01cb9a9b2d974e9c8c82690 (patch) | |
| tree | 618eddef2d3ee1468733907ca0c36b383c47b669 /compat/strerror.cpp | |
| parent | 2eec1c1e4c383c64cafe2e2f23fbc9aa1b96ccbf (diff) | |
a
Diffstat (limited to 'compat/strerror.cpp')
| -rw-r--r-- | compat/strerror.cpp | 19 |
1 files changed, 12 insertions, 7 deletions
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 |
