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

Commit a63d216

Browse files
committed
Fix strerror_r by checking return type from configure.
1 parent 9136613 commit a63d216

File tree

5 files changed

+87
-8
lines changed

5 files changed

+87
-8
lines changed

config/c-library.m4

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Macros that test various C library quirks
2-
# $PostgreSQL: pgsql/config/c-library.m4,v 1.25 2004/03/20 15:39:27 momjian Exp $
2+
# $PostgreSQL: pgsql/config/c-library.m4,v 1.26 2004/06/07 22:39:44 momjian Exp $
33

44

55
# PGAC_VAR_INT_TIMEZONE
@@ -96,6 +96,23 @@ fi
9696
])# PGAC_FUNC_GETPWUID_R_5ARG
9797

9898

99+
# PGAC_FUNC_STRERROR_R_INT
100+
# ---------------------------
101+
# Check if strerror_r() returns an int (SUSv3) rather than a char * (GNU libc)
102+
# If so, define STRERROR_R_INT
103+
AC_DEFUN([PGAC_FUNC_STRERROR_R_INT],
104+
[AC_CACHE_CHECK(whether strerror_r returns int,
105+
pgac_func_strerror_r_int,
106+
[AC_TRY_COMPILE([#include <string.h>],
107+
[int strerror_r(int, char *, size_t);],
108+
[pgac_func_strerror_r_int=yes],
109+
[pgac_func_strerror_r_int=no])])
110+
if test x"$pgac_func_strerror_r_int" = xyes ; then
111+
AC_DEFINE(STRERROR_R_INT,, [Define to 1 if strerror_r() returns a int.])
112+
fi
113+
])# PGAC_FUNC_STRERROR_R_INT
114+
115+
99116
# PGAC_UNION_SEMUN
100117
# ----------------
101118
# Check if `union semun' exists. Define HAVE_UNION_SEMUN if so.

configure

+53
Original file line numberDiff line numberDiff line change
@@ -13759,6 +13759,59 @@ _ACEOF
1375913759

1376013760
fi
1376113761

13762+
echo "$as_me:$LINENO: checking whether strerror_r returns int" >&5
13763+
echo $ECHO_N "checking whether strerror_r returns int... $ECHO_C" >&6
13764+
if test "${pgac_func_strerror_r_int+set}" = set; then
13765+
echo $ECHO_N "(cached) $ECHO_C" >&6
13766+
else
13767+
cat >conftest.$ac_ext <<_ACEOF
13768+
#line $LINENO "configure"
13769+
#include "confdefs.h"
13770+
#include <string.h>
13771+
#ifdef F77_DUMMY_MAIN
13772+
# ifdef __cplusplus
13773+
extern "C"
13774+
# endif
13775+
int F77_DUMMY_MAIN() { return 1; }
13776+
#endif
13777+
int
13778+
main ()
13779+
{
13780+
int strerror_r(int, char *, size_t);
13781+
;
13782+
return 0;
13783+
}
13784+
_ACEOF
13785+
rm -f conftest.$ac_objext
13786+
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
13787+
(eval $ac_compile) 2>&5
13788+
ac_status=$?
13789+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
13790+
(exit $ac_status); } &&
13791+
{ ac_try='test -s conftest.$ac_objext'
13792+
{ (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
13793+
(eval $ac_try) 2>&5
13794+
ac_status=$?
13795+
echo "$as_me:$LINENO: \$? = $ac_status" >&5
13796+
(exit $ac_status); }; }; then
13797+
pgac_func_strerror_r_int=yes
13798+
else
13799+
echo "$as_me: failed program was:" >&5
13800+
cat conftest.$ac_ext >&5
13801+
pgac_func_strerror_r_int=no
13802+
fi
13803+
rm -f conftest.$ac_objext conftest.$ac_ext
13804+
fi
13805+
echo "$as_me:$LINENO: result: $pgac_func_strerror_r_int" >&5
13806+
echo "${ECHO_T}$pgac_func_strerror_r_int" >&6
13807+
if test x"$pgac_func_strerror_r_int" = xyes ; then
13808+
13809+
cat >>confdefs.h <<\_ACEOF
13810+
#define STRERROR_R_INT
13811+
_ACEOF
13812+
13813+
fi
13814+
1376213815

1376313816
else
1376413817
# do not use values from template file

configure.in

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
dnl Process this file with autoconf to produce a configure script.
2-
dnl $PostgreSQL: pgsql/configure.in,v 1.360 2004/05/28 20:52:42 momjian Exp $
2+
dnl $PostgreSQL: pgsql/configure.in,v 1.361 2004/06/07 22:39:43 momjian Exp $
33
dnl
44
dnl Developers, please strive to achieve this order:
55
dnl
@@ -993,6 +993,7 @@ CFLAGS="$_CFLAGS"
993993
LIBS="$_LIBS"
994994

995995
PGAC_FUNC_GETPWUID_R_5ARG
996+
PGAC_FUNC_STRERROR_R_INT
996997

997998
else
998999
# do not use values from template file

src/include/pg_config.h.in

+3
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,9 @@
607607
/* Define to 1 if you have the ANSI C header files. */
608608
#undef STDC_HEADERS
609609

610+
/* Define to 1 if strerror_r() returns a int. */
611+
#undef STRERROR_R_INT
612+
610613
/* Define to 1 if your <sys/time.h> declares `struct tm'. */
611614
#undef TM_IN_SYS_TIME
612615

src/port/thread.c

+11-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
99
*
10-
* $PostgreSQL: pgsql/src/port/thread.c,v 1.20 2004/04/23 18:15:55 momjian Exp $
10+
* $PostgreSQL: pgsql/src/port/thread.c,v 1.21 2004/06/07 22:39:45 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -70,12 +70,17 @@ pqStrerror(int errnum, char *strerrbuf, size_t buflen)
7070
{
7171
#if defined(FRONTEND) && defined(ENABLE_THREAD_SAFETY) && defined(HAVE_STRERROR_R)
7272
/* reentrant strerror_r is available */
73-
/* some early standards had strerror_r returning char * */
74-
strerror_r(errnum, strerrbuf, buflen);
75-
return strerrbuf;
76-
73+
#ifdef STRERROR_R_INT
74+
/* SUSv3 version */
75+
if (strerror_r(errnum, strerrbuf, buflen) == 0)
76+
return strerrbuf;
77+
else
78+
return NULL;
79+
#else
80+
/* GNU libc */
81+
return strerror_r(errnum, strerrbuf, buflen);
82+
#endif
7783
#else
78-
7984
/* no strerror_r() available, just use strerror */
8085
StrNCpy(strerrbuf, strerror(errnum), buflen);
8186

0 commit comments

Comments
 (0)