Em 01/02/2021 18:35, Mark Wielaard escreveu:
Hi Érico,

On Mon, Feb 01, 2021 at 03:56:26PM -0300, Érico Nogueira via Elfutils-devel 
wrote:
Some C libraries don't provide the GNU version of strerror_r, only the
XSI-compliant one. We use the GNU version when available, since it fits
the code better, and otherwise use the XSI-compliant one.

Could you also mention this bug in the commit message?
https://sourceware.org/bugzilla/show_bug.cgi?id=21010

Will do!


If possible, I'd like to get this patch in before the release, otherwise
it's an easy one to carry locally.

One other comment, but this looks good to go otherwise.

diff --git a/configure.ac b/configure.ac
index 346ab800..baf6faf5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -428,6 +428,18 @@ AC_CHECK_DECLS([mempcpy],[],[],
AC_CHECK_FUNCS([process_vm_readv]) +AC_CACHE_CHECK([whether C library provides GNU strerror_r], ac_cv_gnu_strerror_r, [dnl
+old_CFLAGS="$CFLAGS"
+CFLAGS="$CFLAGS -Werror"
+AC_COMPILE_IFELSE([AC_LANG_SOURCE([dnl
+#define _GNU_SOURCE
+#include <string.h>
+char * (*s)(int, char*, size_t) = strerror_r;
+])], ac_cv_gnu_strerror_r=yes, ac_cv_gnu_strerror_r=no)
+CFLAGS="$old_CFLAGS"])
+AS_IF([test "x$ac_cv_gnu_strerror_r" = "xyes"],
+      [AC_DEFINE([HAVE_GNU_STRERROR_R], [1], [Defined if libc has GNU style 
strerror_r])])
+

autoconf comes with the following check:

  - Macro: AC_FUNC_STRERROR_R

     If strerror_r is available, define HAVE_STRERROR_R, and if it is
     declared, define HAVE_DECL_STRERROR_R. If it returns a char *
     message, define STRERROR_R_CHAR_P; otherwise it returns an int
     error number. The Thread-Safe Functions option of Posix requires
     strerror_r to return int, but many systems (including, for
     example, version 2.2.4 of the GNU C Library) return a char * value
     that is not necessarily equal to the buffer argument.

Can we use that instead?

Thank you for pointing me at it :)

I was a bit worried about rolling my own check here, glad to find out there is a standard way of doing it.


+static const char *
+errnomsg(int error)
+{
+  /* Won't be changed by strerror_r, but not const so compiler doesn't throw 
warning */
+  static char unknown[] = "unknown error";
+
+#ifdef HAVE_GNU_STRERROR_R

And use #ifdef STRERROR_R_CHAR_P here?

Thanks,

Mark

Reply via email to