Index: unix/configure
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/configure,v
retrieving revision 1.118
diff -u -r1.118 configure
--- unix/configure	18 Aug 2004 19:59:09 -0000	1.118
+++ unix/configure	24 Sep 2004 06:13:59 -0000
@@ -4790,6 +4790,109 @@
 fi
 done
 
+	if test "x$ac_cv_func_readdir_r" = "xyes"; then
+	    # IRIX 5.3 has a 2 arg version of readdir_r
+	    # while other systems have a 3 arg version.
+	    if test "${tcl_cv_two_arg_readdir_r+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/dir.h>
+int
+main ()
+{
+readdir_r(NULL, NULL);
+  ;
+  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
+  tcl_cv_two_arg_readdir_r=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+tcl_cv_two_arg_readdir_r=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+
+	    if test "${tcl_cv_three_arg_readdir_r+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+#include <sys/types.h>
+#include <sys/dir.h>
+int
+main ()
+{
+readdir_r(NULL, NULL, NULL);
+  ;
+  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
+  tcl_cv_three_arg_readdir_r=yes
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+tcl_cv_three_arg_readdir_r=no
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+fi
+
+	    if test "x$tcl_cv_two_arg_readdir_r" = "xyes" ; then
+	        cat >>confdefs.h <<\_ACEOF
+#define HAVE_TWO_ARG_READDIR_R 1
+_ACEOF
+
+	    elif test "x$tcl_cv_two_arg_readdir_r" = "xyes" ; then
+	        cat >>confdefs.h <<\_ACEOF
+#define HAVE_THREE_ARG_READDIR_R 1
+_ACEOF
+
+	    else
+	        { { echo "$as_me:$LINENO: error: unknown number of args for readdir_r" >&5
+echo "$as_me: error: unknown number of args for readdir_r" >&2;}
+   { (exit 1); exit 1; }; }
+	    fi
+	fi
     else
 	TCL_THREADS=0
 	echo "$as_me:$LINENO: result: no (default)" >&5
Index: unix/tcl.m4
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tcl.m4,v
retrieving revision 1.121
diff -u -r1.121 tcl.m4
--- unix/tcl.m4	18 Aug 2004 19:59:11 -0000	1.121
+++ unix/tcl.m4	24 Sep 2004 06:13:59 -0000
@@ -488,6 +488,25 @@
 	fi
 	LIBS=$ac_saved_libs
 	AC_CHECK_FUNCS(readdir_r)
+	if test "x$ac_cv_func_readdir_r" = "xyes"; then
+	    # IRIX 5.3 has a 2 arg version of readdir_r
+	    # while other systems have a 3 arg version.
+	    AC_CACHE_VAL(tcl_cv_two_arg_readdir_r,
+	        AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/dir.h>], [readdir_r(NULL, NULL);],
+	        tcl_cv_two_arg_readdir_r=yes, tcl_cv_two_arg_readdir_r=no))
+	    AC_CACHE_VAL(tcl_cv_three_arg_readdir_r,
+	        AC_TRY_COMPILE([#include <sys/types.h>
+#include <sys/dir.h>], [readdir_r(NULL, NULL, NULL);],
+	        tcl_cv_three_arg_readdir_r=yes, tcl_cv_three_arg_readdir_r=no))
+	    if test "x$tcl_cv_two_arg_readdir_r" = "xyes" ; then
+	        AC_DEFINE(HAVE_TWO_ARG_READDIR_R)
+	    elif test "x$tcl_cv_two_arg_readdir_r" = "xyes" ; then
+	        AC_DEFINE(HAVE_THREE_ARG_READDIR_R)
+	    else
+	        AC_MSG_ERROR([unknown number of args for readdir_r])
+	    fi
+	fi
     else
 	TCL_THREADS=0
 	AC_MSG_RESULT([no (default)])
Index: unix/tclUnixThrd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/unix/tclUnixThrd.c,v
retrieving revision 1.35
diff -u -r1.35 tclUnixThrd.c
--- unix/tclUnixThrd.c	10 Aug 2004 19:40:48 -0000	1.35
+++ unix/tclUnixThrd.c	24 Sep 2004 06:13:59 -0000
@@ -883,8 +883,12 @@
     ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
 
 #ifdef HAVE_READDIR_R
-    ent = &tsdPtr->rdbuf.ent; 
+    ent = &tsdPtr->rdbuf.ent;
+# ifdef HAVE_TWO_ARG_READDIR_R
+    if (TclOSreaddir_r(dir, ent) != 0) {
+# else /* HAVE_THREE_ARG_READDIR_R */
     if (TclOSreaddir_r(dir, ent, &ent) != 0) {
+# endif /* HAVE_TWO_ARG_READDIR_R */
 	ent = NULL;
     }
 
