Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 2855421

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 e315bd7 commit 2855421

File tree

4 files changed

+15
-17
lines changed

4 files changed

+15
-17
lines changed

config/c-library.m4

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,23 +81,23 @@ AH_VERBATIM(GETTIMEOFDAY_1ARG_,
8181

8282
# PGAC_FUNC_STRERROR_R_INT
8383
# ---------------------------
84-
# Check if strerror_r() returns an int (SUSv3) rather than a char * (GNU libc)
85-
# If so, define STRERROR_R_INT
84+
# Check if strerror_r() returns int (POSIX) rather than char * (GNU libc).
85+
# If so, define STRERROR_R_INT.
86+
# The result is uncertain if strerror_r() isn't provided,
87+
# but we don't much care.
8688
AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
8789
[AC_CACHE_CHECK(whether strerror_r returns int,
8890
pgac_cv_func_strerror_r_int,
8991
[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([#include <string.h>],
90-
[#ifndef _AIX
91-
int strerror_r(int, char *, size_t);
92-
#else
93-
/* Older AIX has 'int' for the third argument so we don't test the args. */
94-
int strerror_r();
95-
#endif])],
92+
[[char buf[100];
93+
switch (strerror_r(1, buf, sizeof(buf)))
94+
{ case 0: break; default: break; }
95+
]])],
9696
[pgac_cv_func_strerror_r_int=yes],
9797
[pgac_cv_func_strerror_r_int=no])])
9898
if test x"$pgac_cv_func_strerror_r_int" = xyes ; then
9999
AC_DEFINE(STRERROR_R_INT, 1,
100-
[Define to 1 if strerror_r() returns a int.])
100+
[Define to 1 if strerror_r() returns int.])
101101
fi
102102
])# PGAC_FUNC_STRERROR_R_INT
103103

configure

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8583,12 +8583,10 @@ else
85838583
int
85848584
main ()
85858585
{
8586-
#ifndef _AIX
8587-
int strerror_r(int, char *, size_t);
8588-
#else
8589-
/* Older AIX has 'int' for the third argument so we don't test the args. */
8590-
int strerror_r();
8591-
#endif
8586+
char buf[100];
8587+
switch (strerror_r(1, buf, sizeof(buf)))
8588+
{ case 0: break; default: break; }
8589+
85928590
;
85938591
return 0;
85948592
}

src/include/pg_config.h.in

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

819-
/* Define to 1 if strerror_r() returns a int. */
819+
/* Define to 1 if strerror_r() returns int. */
820820
#undef STRERROR_R_INT
821821

822822
/* 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
@@ -620,7 +620,7 @@
620620
/* Define to 1 if you have the ANSI C header files. */
621621
#define STDC_HEADERS 1
622622

623-
/* Define to 1 if strerror_r() returns a int. */
623+
/* Define to 1 if strerror_r() returns int. */
624624
/* #undef STRERROR_R_INT */
625625

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

0 commit comments

Comments
 (0)