From 31134c260196458d981c3a9d0923c6d56a1108aa Mon Sep 17 00:00:00 2001 From: DMG Date: Thu, 21 Nov 2024 15:03:56 -0800 Subject: [PATCH] Fix: Improve Definition of PST_STR_ERROR_R Aross Platforms winornix.h, pist_strerror_r.h, pist_strerror_r.cc: Wrap strerror_r for Apple GCC case (Apple GCC defaults to XSI strerror_r, which is not the strerror_r we want). Fixes compile error for GCC on macOS. Also: winornix.h: we wrap errno.h with pst_errno.h in all non-Linux cases. Fixes a compile issue on openBSD. --- include/pistache/pist_strerror_r.h | 8 ++++---- include/pistache/winornix.h | 7 ++++--- src/common/pist_strerror_r.cc | 5 ++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/pistache/pist_strerror_r.h b/include/pistache/pist_strerror_r.h index 282bd9a14..78c84b0bc 100644 --- a/include/pistache/pist_strerror_r.h +++ b/include/pistache/pist_strerror_r.h @@ -15,12 +15,12 @@ /* ------------------------------------------------------------------------- */ -#if defined _IS_WINDOWS || !defined(__GNUC__) || defined(__clang__) \ - || defined(__NetBSD__) +#if !defined(__linux__) && ((!defined(__GNUC__)) || (defined(__MINGW32__)) \ + || (defined(__clang__)) || (defined(__NetBSD__)) || (defined(__APPLE__))) /* ------------------------------------------------------------------------- */ -// Note: We use the GNU-specific definition (which returns char *), not the -// XSI-compliant definition (which returns int) even in the non-GNU case. +// Note: We provide the GNU-specific/POSIX style (which returns char *), not +// the XSI-compliant definition (which returns int) even in the non-GNU case. extern "C" char * pist_strerror_r(int errnum, char *buf, size_t buflen); diff --git a/include/pistache/winornix.h b/include/pistache/winornix.h index 8de328cae..b1151d156 100644 --- a/include/pistache/winornix.h +++ b/include/pistache/winornix.h @@ -182,8 +182,9 @@ typedef int PST_SOCK_OPT_VAL_T; // Use #include PIST_QUOTE(PST_STRERROR_R_HDR) // mingw gcc doesn't define strerror_r (Oct/2024) +// gcc on macOS does define strerror_r, but the XSI version not the POSIX one #if defined(__linux__) || (defined(__GNUC__) && (!defined(__MINGW32__)) && \ - (!defined(__clang__)) && (!defined(__NetBSD__))) + (!defined(__clang__)) && (!defined(__NetBSD__)) && (!defined(__APPLE__))) #define PST_STRERROR_R_HDR string.h #define PST_STRERROR_R strerror_r // returns char * #else @@ -312,9 +313,9 @@ typedef struct in_addr PST_IN_ADDR_T; #endif // Use #include PIST_QUOTE(PST_ERRNO_HDR) -#if defined(_IS_WINDOWS) || defined(__APPLE__) +#ifndef __linux__ // pistache/pst_errno.h prevents mingw gcc's bad macro substitution on errno -// Same issue with clang on macOS +// Same issue with clang on macOS and gcc on OpenBSD #define PST_ERRNO_HDR pistache/pst_errno.h #else #define PST_ERRNO_HDR sys/errno.h diff --git a/src/common/pist_strerror_r.cc b/src/common/pist_strerror_r.cc index 02e310bb4..926b13734 100644 --- a/src/common/pist_strerror_r.cc +++ b/src/common/pist_strerror_r.cc @@ -261,7 +261,7 @@ extern "C" char * pist_strerror_r(int errnum, char *buf, size_t buflen) /* ------------------------------------------------------------------------- */ #elif !defined(__linux__) && ((!defined(__GNUC__)) || (defined(__MINGW32__)) \ - || (defined(__clang__)) || (defined(__NetBSD__))) + || (defined(__clang__)) || (defined(__NetBSD__)) || (defined(__APPLE__))) #include @@ -270,8 +270,7 @@ extern "C" char * pist_strerror_r(int errnum, char *buf, size_t buflen) // Note: We use the GNU-specific definition (which returns char *), not the // XSI-compliant definition (which returns int) even in the non-GNU case. -// Since this is not GNUC, we assume native strerror_r is the XSI form -// (returns int) +// Here, we assume native strerror_r is the XSI form (returns int) static const char * const_bad_strerror_parms = "{Invalid strerror_r parms}"; static char bad_strerror_parms_buff[128];