Patch #639371: Remove FreeBSD 5 specific test, test for ctermid_r, setgroups
prototypes explicitly.
diff --git a/configure b/configure
index f6a8cce..c07fae9 100755
--- a/configure
+++ b/configure
@@ -1,5 +1,5 @@
 #! /bin/sh
-# From configure.in Revision: 1.369 .
+# From configure.in Revision: 1.370 .
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.53 for python 2.3.
 #
@@ -1341,10 +1341,6 @@
   # even though select is a POSIX function. Reported by J. Ribbens.
   OpenBSD/2.* | OpenBSD/3.[012])
     define_xopen_source=no;;
-  # On FreeBSD 5.0, chroot and setgroups are not declared if _XOPEN_SOURCE
-  # is define. Reported by M. Recht.
-  FreeBSD/5.0*)
-    define_xopen_source=no;;
 esac
 
 if test $define_xopen_source = yes
@@ -11988,15 +11984,13 @@
 
 
 
-
-
-for ac_func in alarm chown clock confstr ctermid ctermid_r execv \
+for ac_func in alarm chown clock confstr ctermid execv \
  fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
  gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
  hstrerror inet_pton kill killpg lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
  putenv readlink \
- select setegid seteuid setgid setgroups \
+ select setegid seteuid setgid \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime \
  sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
@@ -12220,6 +12214,114 @@
 fi
 rm -f conftest.$ac_objext conftest.$ac_ext
 
+# On some systems (eg. FreeBSD 5), we would find a definition of the
+# functions ctermid_r, setgroups in the library, but no prototype
+# (e.g. because we use _XOPEN_SOURCE). See whether we can take their
+# address to avoid compiler warnings and potential miscompilations
+# because of the missing prototypes.
+
+echo "$as_me:$LINENO: checking for ctermid_r" >&5
+echo $ECHO_N "checking for ctermid_r... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#include "confdefs.h"
+#include <stdio.h>
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+void* p = ctermid_r
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_CTERMID_R 1
+_ACEOF
+
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+echo "$as_me:$LINENO: checking for setgroups" >&5
+echo $ECHO_N "checking for setgroups... $ECHO_C" >&6
+cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#include "confdefs.h"
+#include <unistd.h.h>
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+void* p = setgroups
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+cat >>confdefs.h <<\_ACEOF
+#define HAVE_SETGROUPS 1
+_ACEOF
+
+  echo "$as_me:$LINENO: result: yes" >&5
+echo "${ECHO_T}yes" >&6
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+echo "$as_me:$LINENO: result: no" >&5
+echo "${ECHO_T}no" >&6
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
 # check for openpty and forkpty
 
 
diff --git a/configure.in b/configure.in
index 5531360..ed744ea 100644
--- a/configure.in
+++ b/configure.in
@@ -120,10 +120,6 @@
   # even though select is a POSIX function. Reported by J. Ribbens.
   OpenBSD/2.* | OpenBSD/3.@<:@012@:>@) 
     define_xopen_source=no;;
-  # On FreeBSD 5.0, chroot and setgroups are not declared if _XOPEN_SOURCE
-  # is define. Reported by M. Recht.
-  FreeBSD/5.0*)
-    define_xopen_source=no;;
 esac
 
 if test $define_xopen_source = yes
@@ -1740,13 +1736,13 @@
 AC_MSG_RESULT(MACHDEP_OBJS)
 
 # checks for library functions
-AC_CHECK_FUNCS(alarm chown clock confstr ctermid ctermid_r execv \
+AC_CHECK_FUNCS(alarm chown clock confstr ctermid execv \
  fchdir flock fork fsync fdatasync fpathconf ftime ftruncate \
  gai_strerror getgroups getlogin getpeername getpgid getpid getpwent getwd \
  hstrerror inet_pton kill killpg lchown lstat mkfifo mknod mktime \
  mremap nice pathconf pause plock poll pthread_init \
  putenv readlink \
- select setegid seteuid setgid setgroups \
+ select setegid seteuid setgid \
  setlocale setregid setreuid setsid setpgid setuid setvbuf snprintf \
  sigaction siginterrupt sigrelse strftime strptime \
  sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
@@ -1773,6 +1769,33 @@
   AC_MSG_RESULT(no)
 )
 
+# On some systems (eg. FreeBSD 5), we would find a definition of the
+# functions ctermid_r, setgroups in the library, but no prototype
+# (e.g. because we use _XOPEN_SOURCE). See whether we can take their
+# address to avoid compiler warnings and potential miscompilations
+# because of the missing prototypes.
+
+AC_MSG_CHECKING(for ctermid_r)
+AC_TRY_COMPILE([
+#include "confdefs.h" 
+#include <stdio.h>
+], void* p = ctermid_r,
+  AC_DEFINE(HAVE_CTERMID_R, 1, Define if you have the 'ctermid_r' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
+AC_MSG_CHECKING(for setgroups)
+AC_TRY_COMPILE([
+#include "confdefs.h" 
+#include <unistd.h.h>
+], 
+void* p = setgroups,
+  AC_DEFINE(HAVE_SETGROUPS, 1, Define if you have the 'setgroups' function.)
+  AC_MSG_RESULT(yes),
+  AC_MSG_RESULT(no)
+)
+
 # check for openpty and forkpty
 
 AC_CHECK_FUNCS(openpty,, AC_CHECK_LIB(util,openpty, [AC_DEFINE(HAVE_OPENPTY) LIBS="$LIBS -lutil"]))
diff --git a/pyconfig.h.in b/pyconfig.h.in
index 19a0ab2..b71ecb2 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -59,7 +59,7 @@
 /* Define to 1 if you have the `ctermid' function. */
 #undef HAVE_CTERMID
 
-/* Define to 1 if you have the `ctermid_r' function. */
+/* Define if you have the 'ctermid_r' function. */
 #undef HAVE_CTERMID_R
 
 /* Define to 1 if you have the device macros. */
@@ -348,7 +348,7 @@
 /* Define to 1 if you have the `setgid' function. */
 #undef HAVE_SETGID
 
-/* Define to 1 if you have the `setgroups' function. */
+/* Define if you have the 'setgroups' function. */
 #undef HAVE_SETGROUPS
 
 /* Define to 1 if you have the `setlocale' function. */