From ebe442479545fbfe652656a13a7589a7d9e78c22 Mon Sep 17 00:00:00 2001 From: Grant Moyer Date: Fri, 25 Feb 2022 13:28:47 -0500 Subject: [PATCH] Fix remaining posix compatability issues in keyboard_state --- src/modules/keyboard_state.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/modules/keyboard_state.cpp b/src/modules/keyboard_state.cpp index 57defa76..1ac075d6 100644 --- a/src/modules/keyboard_state.cpp +++ b/src/modules/keyboard_state.cpp @@ -24,9 +24,14 @@ class errno_error : public std::runtime_error { std::string error_msg{msg}; error_msg += ": "; - // strerror(3) man page says 1024 should be a big enough buffer to avoid ERANGE - char errno_str[1024] = {}; - strerror_r(err, errno_str, sizeof errno_str); +#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 32) + // strerrorname_np gets the error code's name; it's nice to have, but it's a recent GNU extension + const auto errno_name = strerrorname_np(err); + error_msg += errno_name; + error_msg += " "; +#endif + + const auto errno_str = strerror(err); error_msg += errno_str; return error_msg;