Skip to content

Commit 08aad3c

Browse files
committed
Fix detection of the result type of strerror_r().
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 751f532. 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
1 parent 14ce78e commit 08aad3c

File tree

4 files changed

+17
-18
lines changed

4 files changed

+17
-18
lines changed

config/c-library.m4

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,23 @@ fi
102102

103103
# PGAC_FUNC_STRERROR_R_INT
104104
# ---------------------------
105-
# Check if strerror_r() returns an int (SUSv3) rather than a char * (GNU libc)
106-
# If so, define STRERROR_R_INT
105+
# Check if strerror_r() returns int (POSIX) rather than char * (GNU libc).
106+
# If so, define STRERROR_R_INT.
107+
# The result is uncertain if strerror_r() isn't provided,
108+
# but we don't much care.
107109
AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
108110
[AC_CACHE_CHECK(whether strerror_r returns int,
109111
pgac_cv_func_strerror_r_int,
110112
[AC_TRY_COMPILE([#include <string.h>],
111-
[#ifndef _AIX
112-
int strerror_r(int, char *, size_t);
113-
#else
114-
/* Older AIX has 'int' for the third argument so we don't test the args. */
115-
int strerror_r();
116-
#endif],
113+
[char buf[100];
114+
switch (strerror_r(1, buf, sizeof(buf)))
115+
{ case 0: break; default: break; }
116+
],
117117
[pgac_cv_func_strerror_r_int=yes],
118118
[pgac_cv_func_strerror_r_int=no])])
119119
if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
120-
AC_DEFINE(STRERROR_R_INT,, [Define to 1 if strerror_r() returns a int.])
120+
AC_DEFINE(STRERROR_R_INT, 1,
121+
[Define to 1 if strerror_r() returns int.])
121122
fi
122123
])# PGAC_FUNC_STRERROR_R_INT
123124

configure

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24978,12 +24978,10 @@ cat >>conftest.$ac_ext <<_ACEOF
2497824978
int
2497924979
main ()
2498024980
{
24981-
#ifndef _AIX
24982-
int strerror_r(int, char *, size_t);
24983-
#else
24984-
/* Older AIX has 'int' for the third argument so we don't test the args. */
24985-
int strerror_r();
24986-
#endif
24981+
char buf[100];
24982+
switch (strerror_r(1, buf, sizeof(buf)))
24983+
{ case 0: break; default: break; }
24984+
2498724985
;
2498824986
return 0;
2498924987
}
@@ -25021,7 +25019,7 @@ $as_echo "$pgac_cv_func_strerror_r_int" >&6; }
2502125019
if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
2502225020

2502325021
cat >>confdefs.h <<\_ACEOF
25024-
#define STRERROR_R_INT /**/
25022+
#define STRERROR_R_INT 1
2502525023
_ACEOF
2502625024

2502725025
fi

src/include/pg_config.h.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@
773773
/* Define to 1 if you have the ANSI C header files. */
774774
#undef STDC_HEADERS
775775

776-
/* Define to 1 if strerror_r() returns a int. */
776+
/* Define to 1 if strerror_r() returns int. */
777777
#undef STRERROR_R_INT
778778

779779
/* Define to 1 if your <sys/time.h> declares `struct tm'. */

src/include/pg_config.h.win32

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@
633633
/* Define to 1 if you have the ANSI C header files. */
634634
#define STDC_HEADERS 1
635635

636-
/* Define to 1 if strerror_r() returns a int. */
636+
/* Define to 1 if strerror_r() returns int. */
637637
/* #undef STRERROR_R_INT */
638638

639639
/* Define to 1 if your <sys/time.h> declares `struct tm'. */

0 commit comments

Comments
 (0)