Tcl Source Code

Artifact [fdcc973e34]
Login

Artifact fdcc973e340d7884dbd407239760aa8c334457c1:

Attachment "win_fs.patch" to ticket [528284ffff] added by mdejong 2002-03-11 06:52:46.
2002-03-10  Mo DeJong  <[email protected]>

	* win/tclWinFCmd.c (DoRenameFile, DoCopyFile, DoDeleteFile,
	DoRemoveJustDirectory): Make sure we don't pass NULL or ""
	as a path name to Win32 API functions since this was
	crashing under Windows 98.

Index: win/tclWinFCmd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinFCmd.c,v
retrieving revision 1.24
diff -u -r1.24 tclWinFCmd.c
--- win/tclWinFCmd.c	8 Mar 2002 23:46:27 -0000	1.24
+++ win/tclWinFCmd.c	10 Mar 2002 23:35:32 -0000
@@ -167,7 +167,18 @@
     int retval = -1;
 
     /*
-     * The moveFileProc below would throw an exception under NT
+     * The MoveFile API acts differently under Win95/98 and NT
+     * WRT NULL and "". Avoid passing these values.
+     */
+
+    if (nativeSrc == NULL || nativeSrc[0] == '\0' ||
+        nativeDst == NULL || nativeDst[0] == '\0') {
+	Tcl_SetErrno(ENOENT);
+	return TCL_ERROR;
+    }
+
+    /*
+     * The MoveFile API would throw an exception under NT
      * if one of the arguments is a char block device.
      */
 
@@ -442,32 +453,19 @@
     int retval = -1;
 
     /*
-     * The copyFileProc below would throw an exception under NT if one
-     * of the arguments is a char block device.
+     * The CopyFile API acts differently under Win95/98 and NT
+     * WRT NULL and "". Avoid passing these values.
      */
 
-    /* 
-     * If 'nativeDst' is NULL, the following code can lock the process
-     * up, at least under Windows2000.  Therefore we have to bail at
-     * that point.
-     */
-    if (nativeDst == NULL) {
-	Tcl_SetErrno(ENOENT);
-        return TCL_ERROR;
-    }
-    
-    /*
-     * Similarly, if 'nativeSrc' is NULL or empty, the following code
-     * locks up the process on WinNT; bail out.
-     */
-    
-    if (nativeSrc == NULL || nativeSrc[0] == '\0') {
+    if (nativeSrc == NULL || nativeSrc[0] == '\0' ||
+        nativeDst == NULL || nativeDst[0] == '\0') {
 	Tcl_SetErrno(ENOENT);
 	return TCL_ERROR;
     }
     
     /*
-     * OK, now try the copy.
+     * The CopyFile API would throw an exception under NT if one
+     * of the arguments is a char block device.
      */
     
     __try {
@@ -556,33 +554,22 @@
     CONST TCHAR *nativePath)	/* Pathname of file to be removed (native). */
 {
     DWORD attr;
-    
-    if ((*tclWinProcs->deleteFileProc)(nativePath) != FALSE) {
-	return TCL_OK;
-    }
-    TclWinConvertError(GetLastError());
 
     /*
-     * Win32s thinks that "" is the same as "." and then reports EISDIR
-     * instead of ENOENT.
+     * The DeleteFile API acts differently under Win95/98 and NT
+     * WRT NULL and "". Avoid passing these values.
      */
 
-    if (nativePath == NULL) {
+    if (nativePath == NULL || nativePath[0] == '\0') {
 	Tcl_SetErrno(ENOENT);
 	return TCL_ERROR;
     }
-        
-    if (tclWinProcs->useWide) {
-	if (((WCHAR *) nativePath)[0] == '\0') {
-	    Tcl_SetErrno(ENOENT);
-	    return TCL_ERROR;
-	}
-    } else {
-	if (((char *) nativePath)[0] == '\0') {
-	    Tcl_SetErrno(ENOENT);
-	    return TCL_ERROR;
-	}
+    
+    if ((*tclWinProcs->deleteFileProc)(nativePath) != FALSE) {
+	return TCL_OK;
     }
+    TclWinConvertError(GetLastError());
+
     if (Tcl_GetErrno() == EACCES) {
         attr = (*tclWinProcs->getFileAttributesProc)(nativePath);
 	if (attr != 0xffffffff) {
@@ -802,32 +789,21 @@
 {
     DWORD attr;
 
-    if ((*tclWinProcs->removeDirectoryProc)(nativePath) != FALSE) {
-	return TCL_OK;
-    }
-    TclWinConvertError(GetLastError());
-
     /*
-     * Win32s thinks that "" is the same as "." and then reports EACCES
-     * instead of ENOENT.
+     * The RemoveDirectory API acts differently under Win95/98 and NT
+     * WRT NULL and "". Avoid passing these values.
      */
 
-    if (nativePath == NULL) {
+    if (nativePath == NULL || nativePath[0] == '\0') {
 	Tcl_SetErrno(ENOENT);
 	goto end;
     }
-	
-    if (tclWinProcs->useWide) {
-	if (((WCHAR *) nativePath)[0] == '\0') {
-	    Tcl_SetErrno(ENOENT);
-	    return TCL_ERROR;
-	}
-    } else {
-	if (((char *) nativePath)[0] == '\0') {
-	    Tcl_SetErrno(ENOENT);
-	    return TCL_ERROR;
-	}
+
+    if ((*tclWinProcs->removeDirectoryProc)(nativePath) != FALSE) {
+	return TCL_OK;
     }
+    TclWinConvertError(GetLastError());
+
     if (Tcl_GetErrno() == EACCES) {
 	attr = (*tclWinProcs->getFileAttributesProc)(nativePath);
 	if (attr != 0xffffffff) {