diff options
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 |