Skip to content

Commit

Permalink
Fix: Improve Definition of PST_STR_ERROR_R Aross Platforms
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgreatwood committed Nov 21, 2024
1 parent 5bdd8a9 commit 31134c2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions include/pistache/pist_strerror_r.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
7 changes: 4 additions & 3 deletions include/pistache/winornix.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions src/common/pist_strerror_r.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pistache/ps_strl.h>

Expand All @@ -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];
Expand Down

0 comments on commit 31134c2

Please sign in to comment.