+ AC_DEFINE(THREADSAFE,1)
+ AC_DEFINE(_THREADSAFE,1)
+
+ dnl this might cause the errno symbol to be
+ dnl replaced with a function to get a thread specific errno.
+ dnl check to see if everything needs to be compiled
+ dnl with the thread libraries
+ AC_CACHE_CHECK([for thread specific errno],
+ [ol_cv_errno_thread_specific], [
+ AC_TRY_LINK([
+#include <errno.h>
+ ], [
+int x = errno;
+ ],
+ [ol_cv_errno_thread_specific=yes],
+ [ol_cv_errno_thread_specific=no])
+ ])
+
+ if test $ol_cv_errno_thread_specific != yes ; then
+ LIBS="$LTHREAD_LIBS $LIBS"
+ LTHREAD_LIBS=""
+ fi
+
+dnl When in thread environment, use
+dnl #if defined( HAVE_REENTRANT_FUNCTIONS ) \
+dnl || defined( HAVE_FUNC_R )
+dnl func_r(...);
+dnl #else
+dnl # if defined( HAVE_THREADS )
+dnl /* lock */
+dnl # endif
+dnl func(...);
+dnl # if defined( HAVE_THREADS )
+dnl /* unlock */
+dnl # endif
+dnl #endif
+dnl
+dnl HAVE_REENTRANT_FUNCTIONS is derived from:
+dnl _POSIX_REENTRANT_FUNCTIONS
+dnl _POSIX_THREAD_SAFE_FUNCTIONS
+dnl _POSIX_THREADSAFE_FUNCTIONS
+dnl
+dnl and is currently defined in lthread.h
+dnl
+dnl HAVE_THREADS is defined by lthread.h iff -UNO_THREADS
+dnl
+dnl libldap/*.c should only include <lthread.h> iff
+dnl LDAP_R_COMPILE is defined. ie:
+dnl #ifdef LDAP_R_COMPILE
+dnl # include LDAP_R_COMPILE
+dnl #endif
+dnl
+dnl LDAP_R_COMIPLE is defined by libldap_r/Makefile.in
+dnl specifically for compiling the threadsafe version of
+dnl the ldap library (-lldap_r).
+dnl
+dnl dnl check for reentrant/threadsafe functions
+dnl dnl
+dnl dnl note: these should only be used when linking
+dnl dnl with $LTHREAD_LIBS
+dnl dnl
+dnl save_CPPFLAGS="$CPPFLAGS"
+dnl save_LIBS="$LIBS"
+dnl LIBS="$LTHREAD_LIBS $LIBS"
+dnl AC_CHECK_FUNCS( \
+dnl strtok_r \
+dnl gmtime_r \
+dnl gethostbyaddr_r gethostbyname_r \
+dnl feof_unlocked unlocked_feof \
+dnl putc_unlocked unlocked_putc \
+dnl flockfile ftrylockfile \
+dnl )
+dnl CPPFLAGS="$save_CPPFLAGS"
+dnl LIBS="$save_LIBS"
+fi