summaryrefslogtreecommitdiffstats
path: root/unix/tclUnixThrd.c
diff options
context:
space:
mode:
authordas <das>2002-06-06 17:37:54 (GMT)
committerdas <das>2002-06-06 17:37:54 (GMT)
commit7710d5c62d5217f563468a0e595c9f71240f351b (patch)
treed8383cffd57ba9b2bb95730e80227456889d0387 /unix/tclUnixThrd.c
parenta119012d510f0e38f924f4c957718b8fd98dee41 (diff)
downloadtcl-7710d5c62d5217f563468a0e595c9f71240f351b.zip
tcl-7710d5c62d5217f563468a0e595c9f71240f351b.tar.gz
tcl-7710d5c62d5217f563468a0e595c9f71240f351b.tar.bz2
* unix/tclUnixThrd.c (TclpReaddir, TclpLocaltime, TclpGmtime):
added mutex wrapped calls to readdir, localtime & gmtime in case their thread-safe *_r counterparts are not available. * unix/tcl.m4: added configure check for readdir_r * unix/tcl.m4 (Darwin): set TCL_DEFAULT_ENCODING to utf-8 on MacOSX (where posix file apis expect utf-8, not iso8859-1). * unix/configure: regen * unix/Makefile.in: set DYLD_LIBRARY_PATH in parallel to LD_LIBRARY_PATH for MacOSX dynamic linker. * generic/tclEnv.c (TclSetEnv): fix env var setting on MacOSX (adapted from patch #524352 by jkbonfield).
Diffstat (limited to 'unix/tclUnixThrd.c')
-rw-r--r--unix/tclUnixThrd.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/unix/tclUnixThrd.c b/unix/tclUnixThrd.c
index 4084cbe..daa49be 100644
--- a/unix/tclUnixThrd.c
+++ b/unix/tclUnixThrd.c
@@ -790,25 +790,58 @@ TclpFinalizeCondition(condPtr)
*----------------------------------------------------------------------
*/
+#ifndef HAVE_READDIR_R
+TCL_DECLARE_MUTEX( rdMutex )
+#undef readdir
+#endif
+
Tcl_DirEntry *
TclpReaddir(DIR * dir)
{
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
Tcl_DirEntry *ent;
+#ifdef HAVE_READDIR_R
ent = &tsdPtr->rdbuf.ent;
if (Tcl_PlatformReaddir_r(dir, ent, &ent) != 0) {
ent = NULL;
}
+#else
+ Tcl_MutexLock( &rdMutex );
+#ifdef HAVE_STRUCT_DIRENT64
+ ent = readdir64(dir);
+#else
+ ent = readdir(dir);
+#endif
+ if(ent != NULL) {
+ memcpy( (VOID *) &tsdPtr->rdbuf.ent, (VOID *) ent,
+ sizeof (Tcl_DirEntry) + sizeof (char) * (PATH_MAX+1) );
+ ent = &tsdPtr->rdbuf.ent;
+ }
+ Tcl_MutexUnlock( &rdMutex );
+#endif
return ent;
}
+#if !defined(HAVE_GMTIME_R) || !defined(HAVE_LOCALTIME_R)
+TCL_DECLARE_MUTEX( tmMutex )
+#undef localtime
+#undef gmtime
+#endif
+
struct tm *
TclpLocaltime(time_t * clock)
{
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+#ifdef HAVE_LOCALTIME_R
return localtime_r(clock, &tsdPtr->ltbuf);
+#else
+ Tcl_MutexLock( &tmMutex );
+ memcpy( (VOID *) &tsdPtr->ltbuf, (VOID *) localtime( clock ), sizeof (struct tm) );
+ Tcl_MutexUnlock( &tmMutex );
+ return &tsdPtr->ltbuf;
+#endif
}
struct tm *
@@ -816,7 +849,14 @@ TclpGmtime(time_t * clock)
{
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
+#ifdef HAVE_GMTIME_R
return gmtime_r(clock, &tsdPtr->gtbuf);
+#else
+ Tcl_MutexLock( &tmMutex );
+ memcpy( (VOID *) &tsdPtr->gtbuf, (VOID *) gmtime( clock ), sizeof (struct tm) );
+ Tcl_MutexUnlock( &tmMutex );
+ return &tsdPtr->gtbuf;
+#endif
}
char *