Do not define _POSIX_THREADS if unistd.h defines it.
Check for pthread_sigmask before using it. Fixes remaining problem in #470781.
diff --git a/configure.in b/configure.in
index 9846dd2..108d239 100644
--- a/configure.in
+++ b/configure.in
@@ -968,7 +968,6 @@
 elif test "$ac_cv_pthread_is_default" = yes
 then
     AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     # Defining _REENTRANT on system with POSIX threads should not hurt.
     AC_DEFINE(_REENTRANT)
     posix_threads=yes
@@ -977,7 +976,6 @@
 then
     CC="$CC -Kpthread"
     AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     posix_threads=yes
     LIBOBJS="$LIBOBJS thread.o"
 else
@@ -987,6 +985,18 @@
     if test ! -z "$withval" -a -d "$withval"
     then LDFLAGS="$LDFLAGS -L$withval"
     fi
+
+    # According to the POSIX spec, a pthreads implementation must
+    # define _POSIX_THREADS in unistd.h. Some apparently don't (which ones?)
+    AC_MSG_CHECKING(for _POSIX_THREADS in unistd.h)
+    AC_EGREP_CPP(yes,
+    [#include <unistd.h>
+     #ifdef _POSIX_THREADS
+     yes
+     #endif
+    ], unistd_defines_pthreads=yes, unistd_defines_pthreads=no)
+    AC_MSG_RESULT($unistd_defines_pthreads)
+
     AC_DEFINE(_REENTRANT)
     AC_CHECK_HEADER(mach/cthreads.h, [AC_DEFINE(WITH_THREAD)
     AC_DEFINE(C_THREADS)
@@ -1013,47 +1023,32 @@
 pthread_create (NULL, NULL, start_routine, NULL)], [
     AC_MSG_RESULT(yes)
     AC_DEFINE(WITH_THREAD)
-    case $ac_sys_system in
-      Darwin*) ;;
-      *) AC_DEFINE(_POSIX_THREADS)
-         posix_threads=yes
-         ;;
-    esac
+    posix_threads=yes
     LIBOBJS="$LIBOBJS thread.o"],[
     LIBS=$_libs
     AC_CHECK_FUNC(pthread_detach, [AC_DEFINE(WITH_THREAD)
-    case $ac_sys_system in
-      Darwin*) ;;
-      *) AC_DEFINE(_POSIX_THREADS)
-         posix_threads=yes
-         ;;
-    esac
+    posix_threads=yes
     LIBOBJS="$LIBOBJS thread.o"],[
     AC_CHECK_HEADER(kernel/OS.h, [AC_DEFINE(WITH_THREAD)
     AC_DEFINE(BEOS_THREADS)
     LIBOBJS="$LIBOBJS thread.o"],[
     AC_CHECK_LIB(pthreads, pthread_create, [AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     posix_threads=yes
     LIBS="$LIBS -lpthreads"
     LIBOBJS="$LIBOBJS thread.o"], [
     AC_CHECK_LIB(c_r, pthread_create, [AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     posix_threads=yes
     LIBS="$LIBS -lc_r"
     LIBOBJS="$LIBOBJS thread.o"], [
     AC_CHECK_LIB(thread, __d6_pthread_create, [AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     posix_threads=yes
     LIBS="$LIBS -lthread"
     LIBOBJS="$LIBOBJS thread.o"], [
     AC_CHECK_LIB(pthread, __pthread_create_system, [AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     posix_threads=yes
     LIBS="$LIBS -lpthread"
     LIBOBJS="$LIBOBJS thread.o"], [
     AC_CHECK_LIB(cma, pthread_create, [AC_DEFINE(WITH_THREAD)
-    AC_DEFINE(_POSIX_THREADS)
     posix_threads=yes
     LIBS="$LIBS -lcma"
     LIBOBJS="$LIBOBJS thread.o"],[
@@ -1061,6 +1056,10 @@
     ])])])])])])])])])
 
     if test "$posix_threads" = "yes"; then
+      if test "$unistd_defines_pthreads" = "no"; then
+         AC_DEFINE(_POSIX_THREADS)
+      fi
+
       AC_MSG_CHECKING(if PTHREAD_SCOPE_SYSTEM is supported)
       AC_CACHE_VAL(ac_cv_pthread_system_supported,
       [AC_TRY_RUN([#include <pthread.h>
@@ -1082,6 +1081,7 @@
       if test "$ac_cv_pthread_system_supported" = "yes"; then
         AC_DEFINE(PTHREAD_SYSTEM_SCHED_SUPPORTED)
       fi
+      AC_CHECK_FUNCS(pthread_sigmask)
     fi
 
     AC_CHECK_LIB(mpc, usconfig, [AC_DEFINE(WITH_THREAD)