Fix detection of the result type of strerror_r().
authorTom Lane
Sun, 30 Sep 2018 20:24:56 +0000 (16:24 -0400)
committerTom Lane
Sun, 30 Sep 2018 20:24:56 +0000 (16:24 -0400)
The method we've traditionally used, of redeclaring strerror_r() to
see if the compiler complains of inconsistent declarations, turns out
not to work reliably because some compilers only report a warning,
not an error.  Amazingly, this has gone undetected for years, even
though it certainly breaks our detection of whether strerror_r
succeeded.

Let's instead test whether the compiler will take the result of
strerror_r() as a switch() argument.  It's possible this won't
work universally either, but it's the best idea I could come up with
on the spur of the moment.

Back-patch of commit 751f532b9.  Buildfarm results indicate that only
icc-on-Linux actually has an issue here; perhaps the lack of field
reports indicates that people don't build PG for production that way.

Discussion: https://postgr.es/m/10877.1537993279@sss.pgh.pa.us

config/c-library.m4
configure
src/include/pg_config.h.in
src/include/pg_config.h.win32

index 4446a5b71945d2a560b2ad39ca07dffb9dd80ef6..c9067e51c877c9eed54623ac6ca1e6f5fb8487d3 100644 (file)
@@ -82,23 +82,23 @@ AH_VERBATIM(GETTIMEOFDAY_1ARG_,
 
 # PGAC_FUNC_STRERROR_R_INT
 # ---------------------------
-# Check if strerror_r() returns an int (SUSv3) rather than a char * (GNU libc)
-# If so, define STRERROR_R_INT
+# Check if strerror_r() returns int (POSIX) rather than char * (GNU libc).
+# If so, define STRERROR_R_INT.
+# The result is uncertain if strerror_r() isn't provided,
+# but we don't much care.
 AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
 [AC_CACHE_CHECK(whether strerror_r returns int,
 pgac_cv_func_strerror_r_int,
 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include ],
-[#ifndef _AIX
-int strerror_r(int, char *, size_t);
-#else
-/* Older AIX has 'int' for the third argument so we don't test the args. */
-int strerror_r();
-#endif])],
+[[char buf[100];
+  switch (strerror_r(1, buf, sizeof(buf)))
+  { case 0: break; default: break; }
+]])],
 [pgac_cv_func_strerror_r_int=yes],
 [pgac_cv_func_strerror_r_int=no])])
 if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
   AC_DEFINE(STRERROR_R_INT, 1,
-            [Define to 1 if strerror_r() returns int.])
+            [Define to 1 if strerror_r() returns int.])
 fi
 ])# PGAC_FUNC_STRERROR_R_INT
 
index 52308bcdb3da586609e2eb3b077f4a2f3eefcdd7..2511b765a4dfd7d1b5faececb52e7fa614571768 100755 (executable)
--- a/configure
+++ b/configure
@@ -10566,12 +10566,10 @@ else
 int
 main ()
 {
-#ifndef _AIX
-int strerror_r(int, char *, size_t);
-#else
-/* Older AIX has 'int' for the third argument so we don't test the args. */
-int strerror_r();
-#endif
+char buf[100];
+  switch (strerror_r(1, buf, sizeof(buf)))
+  { case 0: break; default: break; }
+
   ;
   return 0;
 }
index be9d5647c1e5db2575ee7184cce962531349b042..2fae82ccc5823fa44b9a629cf49b7e65b5bfdff7 100644 (file)
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
-/* Define to 1 if strerror_r() returns int. */
+/* Define to 1 if strerror_r() returns int. */
 #undef STRERROR_R_INT
 
 /* Define to 1 if your  declares `struct tm'. */
index 26122990eedcbec21188ef9f31939d4eac2cbd85..abea7e8f9c977c7bd390c16ccf48135a9e1bb999 100644 (file)
 /* Define to 1 if you have the ANSI C header files. */
 #define STDC_HEADERS 1
 
-/* Define to 1 if strerror_r() returns int. */
+/* Define to 1 if strerror_r() returns int. */
 /* #undef STRERROR_R_INT */
 
 /* Define to 1 if your  declares `struct tm'. */