summaryrefslogtreecommitdiffstats
path: root/win
diff options
context:
space:
mode:
authorvincentdarley <vincentdarley@noemail.net>2005-03-15 18:07:50 (GMT)
committervincentdarley <vincentdarley@noemail.net>2005-03-15 18:07:50 (GMT)
commit4467ab4b1c7470c5980142b2a4cc425128e728ea (patch)
treeebd3a61d6d133f269141b77e19702a8b680806cb /win
parentf7ce1181d63f7a572bcf6f932c03b8b94f547392 (diff)
downloadtcl-4467ab4b1c7470c5980142b2a4cc425128e728ea.zip
tcl-4467ab4b1c7470c5980142b2a4cc425128e728ea.tar.gz
tcl-4467ab4b1c7470c5980142b2a4cc425128e728ea.tar.bz2
fix to file norm, file pathtype on windows reserved filenames
FossilOrigin-Name: ce26c887c6d39d67dedad06f9aae956a63d0870d
Diffstat (limited to 'win')
-rw-r--r--win/tclWinFile.c83
1 files changed, 80 insertions, 3 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index 4e73891..9c37ff4 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.72 2004/12/01 23:18:55 dgp Exp $
+ * RCS: @(#) $Id: tclWinFile.c,v 1.73 2005/03/15 18:07:57 vincentdarley Exp $
*/
//#define _WIN32_WINNT 0x0500
@@ -189,6 +189,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,
@@ -1036,6 +1037,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;
+}
+
/*
*----------------------------------------------------------------------
*
@@ -2351,9 +2398,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;
}
@@ -2447,6 +2507,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;
}