15 #include "absl/base/internal/strerror.h"
23 #include <type_traits>
25 #include "absl/base/internal/errno_saver.h"
29 namespace base_internal {
32 const char* StrErrorAdaptor(
int errnum,
char*
buf,
size_t buflen) {
34 int rc = strerror_s(
buf, buflen, errnum);
35 buf[buflen - 1] =
'\0';
36 if (rc == 0 && strncmp(
buf,
"Unknown error", buflen) == 0) *
buf =
'\0';
41 auto ret = strerror_r(errnum,
buf, buflen);
42 if (std::is_same<decltype(
ret),
int>::
value) {
48 return reinterpret_cast<const char*
>(
ret);
55 const char*
str = StrErrorAdaptor(errnum,
buf,
sizeof buf);
57 snprintf(
buf,
sizeof buf,
"Unknown error %d", errnum);
65 constexpr
int kSysNerr = 135;
67 std::array<std::string, kSysNerr>* NewStrErrorTable() {
68 auto*
table =
new std::array<std::string, kSysNerr>;
69 for (
int i = 0; i < static_cast<int>(
table->size()); ++
i) {
70 (*table)[
i] = StrErrorInternal(i);
79 static const auto*
table = NewStrErrorTable();
80 if (errnum >= 0 && errnum <
static_cast<int>(
table->size())) {
81 return (*
table)[errnum];
83 return StrErrorInternal(errnum);