Skip to content

Commit 725bcb1

Browse files
committed
Add missing errno entries and restore std::array in bwf::Errno
EL2HLT (Linux 51) and ENOATTR (FreeBSD 87, macOS 93) were left as gaps in the per-platform tables and formatted as "Unknown" even though each is defined in that platform's <errno.h>. Verified the tables by compiling and running against the real headers on Linux, macOS, and FreeBSD 14.3. Restore the std::array the table was before this PR; the raw C array was an unintended downgrade, and size() replaces the sizeof divide in the bounds check. Add a std::error_code formatter test next to the existing bwf::Errno cases, since that path was changed too.
1 parent bab8ad5 commit 725bcb1

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

lib/swoc/src/bw_format.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -751,14 +751,14 @@ namespace {
751751
// is a compile error. The long form (the 'l' spec, below) still uses strerror().
752752
// clang-format off
753753
#if defined(__linux__)
754-
static constexpr std::string_view ERRNO_NAMES[] = {
754+
static constexpr std::array<std::string_view, 134> ERRNO_NAMES = {{
755755
/* 0 */ "SUCCESS", "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", "E2BIG",
756756
/* 8 */ "ENOEXEC", "EBADF", "ECHILD", "EAGAIN", "ENOMEM", "EACCES", "EFAULT", "ENOTBLK",
757757
/* 16 */ "EBUSY", "EEXIST", "EXDEV", "ENODEV", "ENOTDIR", "EISDIR", "EINVAL", "ENFILE",
758758
/* 24 */ "EMFILE", "ENOTTY", "ETXTBSY", "EFBIG", "ENOSPC", "ESPIPE", "EROFS", "EMLINK",
759759
/* 32 */ "EPIPE", "EDOM", "ERANGE", "EDEADLK", "ENAMETOOLONG", "ENOLCK", "ENOSYS", "ENOTEMPTY",
760760
/* 40 */ "ELOOP", "", "ENOMSG", "EIDRM", "ECHRNG", "EL2NSYNC", "EL3HLT", "EL3RST",
761-
/* 48 */ "ELNRNG", "EUNATCH", "ENOCSI", "", "EBADE", "EBADR", "EXFULL", "ENOANO",
761+
/* 48 */ "ELNRNG", "EUNATCH", "ENOCSI", "EL2HLT", "EBADE", "EBADR", "EXFULL", "ENOANO",
762762
/* 56 */ "EBADRQC", "EBADSLT", "", "EBFONT", "ENOSTR", "ENODATA", "ETIME", "ENOSR",
763763
/* 64 */ "ENONET", "ENOPKG", "EREMOTE", "ENOLINK", "EADV", "ESRMNT", "ECOMM", "EPROTO",
764764
/* 72 */ "EMULTIHOP", "EDOTDOT", "EBADMSG", "EOVERFLOW", "ENOTUNIQ", "EBADFD", "EREMCHG", "ELIBACC",
@@ -769,9 +769,9 @@ static constexpr std::string_view ERRNO_NAMES[] = {
769769
/* 112 */ "EHOSTDOWN", "EHOSTUNREACH", "EALREADY", "EINPROGRESS", "ESTALE", "EUCLEAN", "ENOTNAM", "ENAVAIL",
770770
/* 120 */ "EISNAM", "EREMOTEIO", "EDQUOT", "ENOMEDIUM", "EMEDIUMTYPE", "ECANCELED", "ENOKEY", "EKEYEXPIRED",
771771
/* 128 */ "EKEYREVOKED", "EKEYREJECTED", "EOWNERDEAD", "ENOTRECOVERABLE", "ERFKILL", "EHWPOISON",
772-
};
772+
}};
773773
#elif defined(__APPLE__)
774-
static constexpr std::string_view ERRNO_NAMES[] = {
774+
static constexpr std::array<std::string_view, 108> ERRNO_NAMES = {{
775775
/* 0 */ "SUCCESS", "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", "E2BIG",
776776
/* 8 */ "ENOEXEC", "EBADF", "ECHILD", "EDEADLK", "ENOMEM", "EACCES", "EFAULT", "ENOTBLK",
777777
/* 16 */ "EBUSY", "EEXIST", "EXDEV", "ENODEV", "ENOTDIR", "EISDIR", "EINVAL", "ENFILE",
@@ -783,12 +783,12 @@ static constexpr std::string_view ERRNO_NAMES[] = {
783783
/* 64 */ "EHOSTDOWN", "EHOSTUNREACH", "ENOTEMPTY", "EPROCLIM", "EUSERS", "EDQUOT", "ESTALE", "EREMOTE",
784784
/* 72 */ "EBADRPC", "ERPCMISMATCH", "EPROGUNAVAIL", "EPROGMISMATCH", "EPROCUNAVAIL", "ENOLCK", "ENOSYS", "EFTYPE",
785785
/* 80 */ "EAUTH", "ENEEDAUTH", "EPWROFF", "EDEVERR", "EOVERFLOW", "EBADEXEC", "EBADARCH", "ESHLIBVERS",
786-
/* 88 */ "EBADMACHO", "ECANCELED", "EIDRM", "ENOMSG", "EILSEQ", "", "EBADMSG", "EMULTIHOP",
786+
/* 88 */ "EBADMACHO", "ECANCELED", "EIDRM", "ENOMSG", "EILSEQ", "ENOATTR", "EBADMSG", "EMULTIHOP",
787787
/* 96 */ "ENODATA", "ENOLINK", "ENOSR", "ENOSTR", "EPROTO", "ETIME", "EOPNOTSUPP", "ENOPOLICY",
788788
/* 104 */ "ENOTRECOVERABLE", "EOWNERDEAD", "EQFULL", "ENOTCAPABLE",
789-
};
789+
}};
790790
#elif defined(__FreeBSD__)
791-
static constexpr std::string_view ERRNO_NAMES[] = {
791+
static constexpr std::array<std::string_view, 98> ERRNO_NAMES = {{
792792
/* 0 */ "SUCCESS", "EPERM", "ENOENT", "ESRCH", "EINTR", "EIO", "ENXIO", "E2BIG",
793793
/* 8 */ "ENOEXEC", "EBADF", "ECHILD", "EDEADLK", "ENOMEM", "EACCES", "EFAULT", "ENOTBLK",
794794
/* 16 */ "EBUSY", "EEXIST", "EXDEV", "ENODEV", "ENOTDIR", "EISDIR", "EINVAL", "ENFILE",
@@ -799,10 +799,10 @@ static constexpr std::string_view ERRNO_NAMES[] = {
799799
/* 56 */ "EISCONN", "ENOTCONN", "ESHUTDOWN", "ETOOMANYREFS", "ETIMEDOUT", "ECONNREFUSED", "ELOOP", "ENAMETOOLONG",
800800
/* 64 */ "EHOSTDOWN", "EHOSTUNREACH", "ENOTEMPTY", "EPROCLIM", "EUSERS", "EDQUOT", "ESTALE", "EREMOTE",
801801
/* 72 */ "EBADRPC", "ERPCMISMATCH", "EPROGUNAVAIL", "EPROGMISMATCH", "EPROCUNAVAIL", "ENOLCK", "ENOSYS", "EFTYPE",
802-
/* 80 */ "EAUTH", "ENEEDAUTH", "EIDRM", "ENOMSG", "EOVERFLOW", "ECANCELED", "EILSEQ", "",
802+
/* 80 */ "EAUTH", "ENEEDAUTH", "EIDRM", "ENOMSG", "EOVERFLOW", "ECANCELED", "EILSEQ", "ENOATTR",
803803
/* 88 */ "EDOOFUS", "EBADMSG", "EMULTIHOP", "ENOLINK", "EPROTO", "ENOTCAPABLE", "ECAPMODE", "ENOTRECOVERABLE",
804804
/* 96 */ "EOWNERDEAD", "EINTEGRITY",
805-
};
805+
}};
806806
#else
807807
#error "errno name table not defined for this platform"
808808
#endif
@@ -811,7 +811,7 @@ static constexpr std::string_view ERRNO_NAMES[] = {
811811
std::string_view
812812
errno_short_name(int e)
813813
{
814-
if (e >= 0 && e < static_cast<int>(sizeof(ERRNO_NAMES) / sizeof(ERRNO_NAMES[0])) && !ERRNO_NAMES[e].empty()) {
814+
if (e >= 0 && e < static_cast<int>(ERRNO_NAMES.size()) && !ERRNO_NAMES[e].empty()) {
815815
return ERRNO_NAMES[e];
816816
}
817817
return "Unknown"sv;

lib/swoc/unit_tests/test_bw_format.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <variant>
1010
#include <cmath>
1111
#include <cerrno>
12+
#include <string>
13+
#include <system_error>
1214

1315
#include <netinet/in.h>
1416

@@ -558,6 +560,13 @@ TEST_CASE("bwstring std formats", "[libswoc][bwprint]") {
558560
w.clear().print("{:s:s}", swoc::bwf::Errno(ECONNREFUSED));
559561
REQUIRE(w.view() == "ECONNREFUSED"sv);
560562

563+
// The std::error_code formatter routes through the same per-platform table,
564+
// rendering "<name> [<value>]". Build the expectation from the macro so the
565+
// numeric part matches the running platform's numbering.
566+
std::string ec_expected = "ECONNREFUSED [" + std::to_string(ECONNREFUSED) + "]";
567+
w.clear().print("{}", std::error_code(ECONNREFUSED, std::generic_category()));
568+
REQUIRE(w.view() == ec_expected);
569+
561570
time_t t = 1528484137;
562571
// default is GMT
563572
w.clear().print("{} is {}", t, swoc::bwf::Date(t));

0 commit comments

Comments
 (0)