diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-22 11:50:55 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2023-11-22 11:50:55 +0100 |
| commit | baf99d32bc58074f10cf194e43963f47fae34c08 (patch) | |
| tree | a4e80d11a641054db48c8cb2b075d43f3b399b67 /compat/strerror.cpp | |
| parent | 2da189ce7435d44a83e37963e79ca0eb927f4e23 (diff) | |
a
Diffstat (limited to 'compat/strerror.cpp')
| -rw-r--r-- | compat/strerror.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/compat/strerror.cpp b/compat/strerror.cpp new file mode 100644 index 00000000..67b87e2f --- /dev/null +++ b/compat/strerror.cpp @@ -0,0 +1,31 @@ +#include "strerror.hpp" +#include <errno.h> +#include <string.h> + +namespace floormat { + +StringView get_error_string(ArrayView<char> buf) +{ +#ifndef _WIN32 + if constexpr(std::is_same_v<char*, std::decay_t<decltype(::strerror_r(errno, buf.data(), buf.size()))>>) + { + const char* str { ::strerror_r(errno, buf.data(), buf.size()) }; + if (str) + return str; + } + else + { + const int status { ::strerror_r(errno, buf.data(), buf.size()) }; + if (status == 0) + return buf; + } +#else + ::strerror_s(buf.data(), buf.size(), errno); + if (buf[0]) + return buf; +#endif + + return "Unknown error"_s; +}; + +} // namespace floormat |
