summaryrefslogtreecommitdiffstats
path: root/win/tclWinFile.c
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley>2005-03-15 18:08:20 (GMT)
committervincentdarley <vincentdarley>2005-03-15 18:08:20 (GMT)
commit54eca4bde86a1e41d123a643f2aadf95caf433da (patch)
tree3a60d461d0cd76315e91eb297726993947421dcd /win/tclWinFile.c
parentd1efd01d81c6ab8a8172b42147ecb529524894b3 (diff)
downloadtcl-54eca4bde86a1e41d123a643f2aadf95caf433da.zip
tcl-54eca4bde86a1e41d123a643f2aadf95caf433da.tar.gz
tcl-54eca4bde86a1e41d123a643f2aadf95caf433da.tar.bz2
fix to file norm, file pathtype on windows reserved filenames
Diffstat (limited to 'win/tclWinFile.c')
-rw-r--r--win/tclWinFile.c83
1 files changed, 80 insertions, 3 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index 1ad7da8..18c4787 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.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: tclWinFile.c,v 1.44.2.10 2004/10/08 20:16:42 hobbs Exp $
+ * RCS: @(#) $Id: tclWinFile.c,v 1.44.2.11 2005/03/15 18:08:24 vincentdarley Exp $
*/
//#define _WIN32_WINNT 0x0500
@@ -178,6 +178,7 @@ static int NativeWriteReparse(CONST TCHAR* LinkDirectory,
static int NativeMatchType(int isDrive, DWORD attr, CONST TCHAR* nativeName,
Tcl_GlobTypeData *types);
static int WinIsDrive(CONST char *name, int nameLen);
+static int WinIsReserved(CONST char *path);
static Tcl_Obj* WinReadLink(CONST TCHAR* LinkSource);
static Tcl_Obj* WinReadLinkDirectory(CONST TCHAR* LinkDirectory);
static int WinLink(CONST TCHAR* LinkSource, CONST TCHAR* LinkTarget,
@@ -1010,6 +1011,52 @@ WinIsDrive(
return 0;
}
+/*
+ * Does the given path represent a reserved window path name? If not
+ * return 0, if true, return the number of characters of the path that
+ * we actually want (not any trailing :).
+ */
+static int WinIsReserved(
+ CONST char *path) /* Path in UTF-8 */
+{
+ if ((path[0] == 'c' || path[0] == 'C')
+ && (path[1] == 'o' || path[1] == 'O')) {
+ if ((path[2] == 'm' || path[2] == 'M')
+ && path[3] >= '1' && path[3] <= '4') {
+ /* May have match for 'com[1-4]:?', which is a serial port */
+ if (path[4] == '\0') {
+ return 4;
+ } else if (path [4] == ':' && path[5] == '\0') {
+ return 4;
+ }
+ } else if ((path[2] == 'n' || path[2] == 'N') && path[3] == '\0') {
+ /* Have match for 'con' */
+ return 3;
+ }
+ } else if ((path[0] == 'l' || path[0] == 'L')
+ && (path[1] == 'p' || path[1] == 'P')
+ && (path[2] == 't' || path[2] == 'T')) {
+ if (path[3] >= '1' && path[3] <= '3') {
+ /* May have match for 'lpt[1-3]:?' */
+ if (path[4] == '\0') {
+ return 4;
+ } else if (path [4] == ':' && path[5] == '\0') {
+ return 4;
+ }
+ }
+ } else if (stricmp(path, "prn") == 0) {
+ /* Have match for 'prn' */
+ return 3;
+ } else if (stricmp(path, "nul") == 0) {
+ /* Have match for 'nul' */
+ return 3;
+ } else if (stricmp(path, "aux") == 0) {
+ /* Have match for 'aux' */
+ return 3;
+ }
+ return 0;
+}
+
/*
*----------------------------------------------------------------------
*
@@ -2140,9 +2187,22 @@ TclpObjNormalizePath(interp, pathPtr, nextCheckpoint)
* the current normalized path, if the file exists.
*/
if (isDrive) {
- if (GetFileAttributesA(nativePath)
- == 0xffffffff) {
+ if (GetFileAttributesA(nativePath) == 0xffffffff) {
/* File doesn't exist */
+ if (isDrive) {
+ int len = WinIsReserved(path);
+ if (len > 0) {
+ /* Actually it does exist - COM1, etc */
+ int i;
+ for (i=0;i<len;i++) {
+ if (nativePath[i] >= 'a') {
+ ((char*)nativePath)[i] -= ('a' - 'A');
+ }
+ }
+ Tcl_DStringAppend(&dsNorm, nativePath, len);
+ lastValidPathEnd = currentPathEndPosition;
+ }
+ }
Tcl_DStringFree(&ds);
break;
}
@@ -2209,6 +2269,23 @@ TclpObjNormalizePath(interp, pathPtr, nextCheckpoint)
if ((*tclWinProcs->getFileAttributesExProc)(nativePath,
GetFileExInfoStandard, &data) != TRUE) {
/* File doesn't exist */
+ if (isDrive) {
+ int len = WinIsReserved(path);
+ if (len > 0) {
+ /* Actually it does exist - COM1, etc */
+ int i;
+ for (i=0;i<len;i++) {
+ WCHAR wc = ((WCHAR*)nativePath)[i];
+ if (wc >= L'a') {
+ wc -= (L'a' - L'A');
+ ((WCHAR*)nativePath)[i] = wc;
+ }
+ }
+ Tcl_DStringAppend(&dsNorm, nativePath,
+ sizeof(WCHAR)*len);
+ lastValidPathEnd = currentPathEndPosition;
+ }
+ }
Tcl_DStringFree(&ds);
break;
}