From: Stefan Sperling Subject: -portable: fix strerror_r To: gameoftrees@openbsd.org Date: Tue, 21 Sep 2021 10:35:24 +0200 This fixes all remaining cmdline test failures on ubuntu. It looks like autoconf 2.69 will not provide XPG strerror_r even if the appropriate macros are set which request the XPG version. My workaround is to call the xpg version directly. This is ugly but works. It can be fixed once autoconf has been fixed. diff --git a/lib/error.c b/lib/error.c index 4ad6d22a..8fb88683 100644 --- a/lib/error.c +++ b/lib/error.c @@ -90,7 +90,15 @@ got_error_from_errno(const char *prefix) struct got_error *err = &cerr->err; char strerr[128]; +#ifdef __GLIBC__ + /* + * The autoconf test for strerror_r is broken in current versions + * of autoconf: https://savannah.gnu.org/support/?110367 + */ + __xpg_strerror_r(errno, strerr, sizeof(strerr)); +#else strerror_r(errno, strerr, sizeof(strerr)); +#endif snprintf(cerr->msg, sizeof(cerr->msg), "%s: %s", prefix, strerr); err->code = GOT_ERR_ERRNO; @@ -105,7 +113,15 @@ got_error_from_errno2(const char *prefix, const char *prefix2) struct got_error *err = &cerr->err; char strerr[128]; +#ifdef __GLIBC__ + /* + * The autoconf test for strerror_r is broken in current versions + * of autoconf: https://savannah.gnu.org/support/?110367 + */ + __xpg_strerror_r(errno, strerr, sizeof(strerr)); +#else strerror_r(errno, strerr, sizeof(strerr)); +#endif snprintf(cerr->msg, sizeof(cerr->msg), "%s: %s: %s", prefix, prefix2, strerr); @@ -122,7 +138,15 @@ got_error_from_errno3(const char *prefix, const char *prefix2, struct got_error *err = &cerr->err; char strerr[128]; +#ifdef __GLIBC__ + /* + * The autoconf test for strerror_r is broken in current versions + * of autoconf: https://savannah.gnu.org/support/?110367 + */ + __xpg_strerror_r(errno, strerr, sizeof(strerr)); +#else strerror_r(errno, strerr, sizeof(strerr)); +#endif snprintf(cerr->msg, sizeof(cerr->msg), "%s: %s: %s: %s", prefix, prefix2, prefix3, strerr); @@ -144,7 +168,15 @@ got_error_from_errno_fmt(const char *fmt, ...) vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); +#ifdef __GLIBC__ + /* + * The autoconf test for strerror_r is broken in current versions + * of autoconf: https://savannah.gnu.org/support/?110367 + */ + __xpg_strerror_r(errno, strerr, sizeof(strerr)); +#else strerror_r(errno, strerr, sizeof(strerr)); +#endif snprintf(cerr->msg, sizeof(cerr->msg), "%s: %s", buf, strerr); err->code = GOT_ERR_ERRNO;