Skip to content

Commit 751f532

Browse files
committed
Try another way to detect 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. We should probably back-patch this once the dust settles, but first let's see what the buildfarm thinks of it. Discussion: https://postgr.es/m/10877.1537993279@sss.pgh.pa.us
1 parent 8b91d25 commit 751f532

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
@@ -82,23 +82,23 @@ AH_VERBATIM(GETTIMEOFDAY_1ARG_,
8282

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

configure

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10792,12 +10792,10 @@ else
1079210792
int
1079310793
main ()
1079410794
{
10795-
#ifndef _AIX
10796-
int strerror_r(int, char *, size_t);
10797-
#else
10798-
/* Older AIX has 'int' for the third argument so we don't test the args. */
10799-
int strerror_r();
10800-
#endif
10795+
char buf[100];
10796+
switch (strerror_r(1, buf, sizeof(buf)))
10797+
{ case 0: break; default: break; }
10798+
1080110799
;
1080210800
return 0;
1080310801
}

src/include/pg_config.h.in

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

855-
/* Define to 1 if strerror_r() returns a int. */
855+
/* Define to 1 if strerror_r() returns int. */
856856
#undef STRERROR_R_INT
857857

858858
/* 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
@@ -665,7 +665,7 @@
665665
/* Define to 1 if you have the ANSI C header files. */
666666
#define STDC_HEADERS 1
667667

668-
/* Define to 1 if strerror_r() returns a int. */
668+
/* Define to 1 if strerror_r() returns int. */
669669
/* #undef STRERROR_R_INT */
670670

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

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy