summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstanton <stanton>1998-09-28 20:24:18 (GMT)
committerstanton <stanton>1998-09-28 20:24:18 (GMT)
commit94b67f615e361c95e27693c44d54634642ecd81f (patch)
treed270b0a7f036300030b94b96506a44d9327cc12d
parent9995355714bc90faf7c2e345b3d6a1d041447097 (diff)
downloadtcl-94b67f615e361c95e27693c44d54634642ecd81f.zip
tcl-94b67f615e361c95e27693c44d54634642ecd81f.tar.gz
tcl-94b67f615e361c95e27693c44d54634642ecd81f.tar.bz2
fixed stat() and access() usage to use correct routines for wrapper
-rw-r--r--generic/tclCmdAH.c4
-rw-r--r--generic/tclIOUtil.c44
-rw-r--r--unix/tclUnixFCmd.c26
-rw-r--r--unix/tclUnixFile.c33
4 files changed, 68 insertions, 39 deletions
diff --git a/generic/tclCmdAH.c b/generic/tclCmdAH.c
index 5ac1510..f17b8fc 100644
--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -11,7 +11,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclCmdAH.c,v 1.1.2.2 1998/09/24 23:58:42 stanton Exp $
+ * RCS: @(#) $Id: tclCmdAH.c,v 1.1.2.3 1998/09/28 20:24:18 stanton Exp $
*/
#include "tclInt.h"
@@ -1199,7 +1199,7 @@ CheckAccess(interp, objPtr, mode)
if (fileName == NULL) {
value = 0;
} else {
- value = (TclpAccess(fileName, mode) == 0);
+ value = (TclAccess(fileName, mode) == 0);
Tcl_DStringFree(&ds);
}
Tcl_SetBooleanObj(Tcl_GetObjResult(interp), value);
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index 7bdb93f..c80cb9b 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -13,7 +13,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclIOUtil.c,v 1.1.2.2 1998/09/24 23:58:53 stanton Exp $
+ * RCS: @(#) $Id: tclIOUtil.c,v 1.1.2.3 1998/09/28 20:24:18 stanton Exp $
*/
#include "tclInt.h"
@@ -54,7 +54,9 @@ typedef struct OpenFileChannelProc {
* these statically declared list entry cannot be inadvertently removed.
*
* This method avoids the need to call any sort of "initialization"
- * function
+ * function.
+ *
+ * All three lists are protected by a global hookMutex.
*/
static StatProc defaultStatProc = {
@@ -72,6 +74,8 @@ static OpenFileChannelProc defaultOpenFileChannelProc = {
};
static OpenFileChannelProc *openFileChannelProcList =
&defaultOpenFileChannelProc;
+
+static Tcl_Mutex hookMutex;
/*
*---------------------------------------------------------------------------
@@ -293,7 +297,7 @@ Tcl_EvalFile(interp, fileName)
Tcl_DStringAppend(&buffer, nativeName, -1);
nativeName = Tcl_DStringValue(&buffer);
}
- if (TclpStat(nativeName, &statBuf) == -1) {
+ if (TclStat(nativeName, &statBuf) == -1) {
Tcl_SetErrno(errno);
Tcl_AppendResult(interp, "couldn't read file \"", fileName,
"\": ", Tcl_PosixError(interp), (char *) NULL);
@@ -448,7 +452,7 @@ TclStat(path, buf)
CONST char *path; /* Path of file to stat (in current CP). */
TclStat_ *buf; /* Filled with results of stat call. */
{
- StatProc *statProcPtr = statProcList;
+ StatProc *statProcPtr;
int retVal = -1;
/*
@@ -456,10 +460,13 @@ TclStat(path, buf)
* value of -1 indicates the particular function has succeeded.
*/
+ Tcl_MutexLock(&hookMutex);
+ statProcPtr = statProcList;
while ((retVal == -1) && (statProcPtr != NULL)) {
retVal = (*statProcPtr->proc)(path, buf);
statProcPtr = statProcPtr->nextPtr;
}
+ Tcl_MutexUnlock(&hookMutex);
return (retVal);
}
@@ -488,7 +495,7 @@ TclAccess(path, mode)
CONST char *path; /* Path of file to access (in current CP). */
int mode; /* Permission setting. */
{
- AccessProc *accessProcPtr = accessProcList;
+ AccessProc *accessProcPtr;
int retVal = -1;
/*
@@ -496,10 +503,13 @@ TclAccess(path, mode)
* value of -1 indicates the particular function has succeeded.
*/
+ Tcl_MutexLock(&hookMutex);
+ accessProcPtr = accessProcList;
while ((retVal == -1) && (accessProcPtr != NULL)) {
retVal = (*accessProcPtr->proc)(path, mode);
accessProcPtr = accessProcPtr->nextPtr;
}
+ Tcl_MutexUnlock(&hookMutex);
return (retVal);
}
@@ -535,7 +545,7 @@ Tcl_OpenFileChannel(interp, fileName, modeString, permissions)
* file, with what modes to create
* it? */
{
- OpenFileChannelProc *openFileChannelProcPtr = openFileChannelProcList;
+ OpenFileChannelProc *openFileChannelProcPtr;
Tcl_Channel retVal = NULL;
/*
@@ -544,11 +554,14 @@ Tcl_OpenFileChannel(interp, fileName, modeString, permissions)
* succeeded.
*/
+ Tcl_MutexLock(&hookMutex);
+ openFileChannelProcPtr = openFileChannelProcList;
while ((retVal == NULL) && (openFileChannelProcPtr != NULL)) {
retVal = (*openFileChannelProcPtr->proc)(interp, fileName,
modeString, permissions);
openFileChannelProcPtr = openFileChannelProcPtr->nextPtr;
}
+ Tcl_MutexUnlock(&hookMutex);
return (retVal);
}
@@ -588,8 +601,10 @@ TclStatInsertProc (proc)
if (newStatProcPtr != NULL) {
newStatProcPtr->proc = proc;
+ Tcl_MutexLock(&hookMutex);
newStatProcPtr->nextPtr = statProcList;
statProcList = newStatProcPtr;
+ Tcl_MutexUnlock(&hookMutex);
retVal = TCL_OK;
}
@@ -622,9 +637,11 @@ TclStatDeleteProc (proc)
TclStatProc_ *proc;
{
int retVal = TCL_ERROR;
- StatProc *tmpStatProcPtr = statProcList;
+ StatProc *tmpStatProcPtr;
StatProc *prevStatProcPtr = NULL;
+ Tcl_MutexLock(&hookMutex);
+ tmpStatProcPtr = statProcList;
/*
* Traverse the 'statProcList' looking for the particular node
* whose 'proc' member matches 'proc' and remove that one from
@@ -648,6 +665,7 @@ TclStatDeleteProc (proc)
}
}
+ Tcl_MutexUnlock(&hookMutex);
return (retVal);
}
@@ -686,8 +704,10 @@ TclAccessInsertProc(proc)
if (newAccessProcPtr != NULL) {
newAccessProcPtr->proc = proc;
+ Tcl_MutexLock(&hookMutex);
newAccessProcPtr->nextPtr = accessProcList;
accessProcList = newAccessProcPtr;
+ Tcl_MutexUnlock(&hookMutex);
retVal = TCL_OK;
}
@@ -720,7 +740,7 @@ TclAccessDeleteProc(proc)
TclAccessProc_ *proc;
{
int retVal = TCL_ERROR;
- AccessProc *tmpAccessProcPtr = accessProcList;
+ AccessProc *tmpAccessProcPtr;
AccessProc *prevAccessProcPtr = NULL;
/*
@@ -729,6 +749,8 @@ TclAccessDeleteProc(proc)
* the list. Ensure that the "default" node cannot be removed.
*/
+ Tcl_MutexLock(&hookMutex);
+ tmpAccessProcPtr = accessProcList;
while ((retVal == TCL_ERROR) && (tmpAccessProcPtr != &defaultAccessProc)) {
if (tmpAccessProcPtr->proc == proc) {
if (prevAccessProcPtr == NULL) {
@@ -745,6 +767,7 @@ TclAccessDeleteProc(proc)
tmpAccessProcPtr = tmpAccessProcPtr->nextPtr;
}
}
+ Tcl_MutexUnlock(&hookMutex);
return (retVal);
}
@@ -786,8 +809,10 @@ TclOpenFileChannelInsertProc(proc)
if (newOpenFileChannelProcPtr != NULL) {
newOpenFileChannelProcPtr->proc = proc;
+ Tcl_MutexLock(&hookMutex);
newOpenFileChannelProcPtr->nextPtr = openFileChannelProcList;
openFileChannelProcList = newOpenFileChannelProcPtr;
+ Tcl_MutexUnlock(&hookMutex);
retVal = TCL_OK;
}
@@ -829,6 +854,8 @@ TclOpenFileChannelDeleteProc(proc)
* the list. Ensure that the "default" node cannot be removed.
*/
+ Tcl_MutexLock(&hookMutex);
+ tmpOpenFileChannelProcPtr = openFileChannelProcList;
while ((retVal == TCL_ERROR) &&
(tmpOpenFileChannelProcPtr != &defaultOpenFileChannelProc)) {
if (tmpOpenFileChannelProcPtr->proc == proc) {
@@ -847,6 +874,7 @@ TclOpenFileChannelDeleteProc(proc)
tmpOpenFileChannelProcPtr = tmpOpenFileChannelProcPtr->nextPtr;
}
}
+ Tcl_MutexUnlock(&hookMutex);
return (retVal);
}
diff --git a/unix/tclUnixFCmd.c b/unix/tclUnixFCmd.c
index cbcab04..3538328 100644
--- a/unix/tclUnixFCmd.c
+++ b/unix/tclUnixFCmd.c
@@ -10,7 +10,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixFCmd.c,v 1.1.2.2 1998/09/24 23:59:45 stanton Exp $
+ * RCS: @(#) $Id: tclUnixFCmd.c,v 1.1.2.3 1998/09/28 20:24:20 stanton Exp $
*
* Portions of this code were derived from NetBSD source code which has
* the following copyright notice:
@@ -1065,13 +1065,9 @@ GetGroupAttribute(interp, objIndex, fileName, attributePtrPtr)
{
struct stat statBuf;
struct group *groupPtr;
- Tcl_DString ds;
- CONST char *native, *utf;
int result;
- native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
- result = TclStat(native, &statBuf); /* INTL: Native. */
- Tcl_DStringFree(&ds);
+ result = TclStat(fileName, &statBuf);
if (result != 0) {
Tcl_AppendResult(interp, "could not read \"", fileName, "\": ",
@@ -1083,6 +1079,9 @@ GetGroupAttribute(interp, objIndex, fileName, attributePtrPtr)
if (groupPtr == NULL) {
*attributePtrPtr = Tcl_NewIntObj(statBuf.st_gid);
} else {
+ Tcl_DString ds;
+ CONST char *utf;
+
utf = Tcl_ExternalToUtfDString(NULL, groupPtr->gr_name, -1, &ds);
*attributePtrPtr = Tcl_NewStringObj(utf, -1);
Tcl_DStringFree(&ds);
@@ -1117,13 +1116,9 @@ GetOwnerAttribute(interp, objIndex, fileName, attributePtrPtr)
{
struct stat statBuf;
struct passwd *pwPtr;
- Tcl_DString ds;
- CONST char *native, *utf;
int result;
- native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
- result = TclStat(native, &statBuf); /* INTL: Native. */
- Tcl_DStringFree(&ds);
+ result = TclStat(fileName, &statBuf);
if (result != 0) {
Tcl_AppendResult(interp, "could not read \"", fileName, "\": ",
@@ -1135,6 +1130,9 @@ GetOwnerAttribute(interp, objIndex, fileName, attributePtrPtr)
if (pwPtr == NULL) {
*attributePtrPtr = Tcl_NewIntObj(statBuf.st_uid);
} else {
+ Tcl_DString ds;
+ CONST char *utf;
+
utf = Tcl_ExternalToUtfDString(NULL, pwPtr->pw_name, -1, &ds);
*attributePtrPtr = Tcl_NewStringObj(utf, Tcl_DStringLength(&ds));
Tcl_DStringFree(&ds);
@@ -1169,13 +1167,9 @@ GetPermissionsAttribute(interp, objIndex, fileName, attributePtrPtr)
{
struct stat statBuf;
char returnString[6];
- Tcl_DString ds;
- CONST char *native;
int result;
- native = Tcl_UtfToExternalDString(NULL, fileName, -1, &ds);
- result = TclStat(native, &statBuf); /* INTL: Native. */
- Tcl_DStringFree(&ds);
+ result = TclStat(fileName, &statBuf);
if (result != 0) {
Tcl_AppendResult(interp, "could not read \"", fileName, "\": ",
diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c
index 4ba41e9..0208f35 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -9,7 +9,7 @@
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclUnixFile.c,v 1.1.2.2 1998/09/24 23:59:45 stanton Exp $
+ * RCS: @(#) $Id: tclUnixFile.c,v 1.1.2.3 1998/09/28 20:24:20 stanton Exp $
*/
#include "tclInt.h"
@@ -107,8 +107,15 @@ Tcl_FindExecutable(argv0)
}
}
name = Tcl_DStringAppend(&buffer, argv0, -1);
- if ((TclAccess(name, X_OK) == 0) /* INTL: Native. */
- && (TclStat(name, &statBuf) == 0) /* INTL: Native. */
+
+ /*
+ * INTL: The following calls to access() and stat() should not be
+ * converted to Tclp routines because they need to operate on native
+ * strings directly.
+ */
+
+ if ((access(name, X_OK) == 0) /* INTL: Native. */
+ && (stat(name, &statBuf) == 0) /* INTL: Native. */
&& S_ISREG(statBuf.st_mode)) {
goto gotName;
}
@@ -211,13 +218,11 @@ TclpMatchFiles(interp, separators, dirPtr, pattern, tail)
if (Tcl_DStringLength(dirPtr) == 0) {
dirName = ".";
} else {
- dirName = dirPtr->string;
+ dirName = Tcl_DStringValue(dirPtr);
}
- native = Tcl_UtfToExternalDString(NULL, dirName, -1, &ds);
- if ((TclStat(native, &statBuf) != 0) /* INTL: Native. */
+ if ((TclStat(dirName, &statBuf) != 0) /* INTL: Native. */
|| !S_ISDIR(statBuf.st_mode)) {
- Tcl_DStringFree(&ds);
return TCL_OK;
}
@@ -236,6 +241,7 @@ TclpMatchFiles(interp, separators, dirPtr, pattern, tail)
* Now open the directory for reading and iterate over the contents.
*/
+ native = Tcl_UtfToExternalDString(NULL, dirName, -1, &ds);
d = opendir(native); /* INTL: Native. */
Tcl_DStringFree(&ds);
if (d == NULL) {
@@ -246,15 +252,16 @@ TclpMatchFiles(interp, separators, dirPtr, pattern, tail)
*/
if (baseLength > 0) {
- savedChar = dirPtr->string[baseLength-1];
+ savedChar = (Tcl_DStringValue(dirPtr))[baseLength-1];
if (savedChar == '/') {
- dirPtr->string[baseLength-1] = '\0';
+ (Tcl_DStringValue(dirPtr))[baseLength-1] = '\0';
}
}
Tcl_AppendResult(interp, "couldn't read directory \"",
- dirPtr->string, "\": ", Tcl_PosixError(interp), (char *) NULL);
+ Tcl_DStringValue(dirPtr), "\": ",
+ Tcl_PosixError(interp), (char *) NULL);
if (baseLength > 0) {
- dirPtr->string[baseLength-1] = savedChar;
+ (Tcl_DStringValue(dirPtr))[baseLength-1] = savedChar;
}
return TCL_ERROR;
}
@@ -309,8 +316,8 @@ TclpMatchFiles(interp, separators, dirPtr, pattern, tail)
if (tail == NULL) {
Tcl_AppendElement(interp, Tcl_DStringValue(dirPtr));
} else if ((TclStat(Tcl_DStringValue(dirPtr), &statBuf) == 0)
- Tcl_AppendElement(interp, dirPtr->string);
- } else if ((TclStat(dirPtr->string, &statBuf) == 0)
+ Tcl_AppendElement(interp, Tcl_DStringValue(dirPtr));
+ } else if ((TclStat(Tcl_DStringValue(dirPtr), &statBuf) == 0)
&& S_ISDIR(statBuf.st_mode)) {
Tcl_DStringAppend(dirPtr, "/", 1);
result = TclDoGlob(interp, separators, dirPtr, tail);