diff options
Diffstat (limited to 'win/tclWinFile.c')
-rw-r--r--[-rwxr-xr-x] | win/tclWinFile.c | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c index b9787c7..6582ee1 100755..100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -169,7 +169,7 @@ static int NativeWriteReparse(const TCHAR *LinkDirectory, REPARSE_DATA_BUFFER *buffer); static int NativeMatchType(int isDrive, DWORD attr, const TCHAR *nativeName, Tcl_GlobTypeData *types); -static int WinIsDrive(const char *name, int nameLen); +static int WinIsDrive(const char *name, size_t nameLen); static int WinIsReserved(const char *path); static Tcl_Obj * WinReadLink(const TCHAR *LinkSource); static Tcl_Obj * WinReadLinkDirectory(const TCHAR *LinkDirectory); @@ -572,7 +572,6 @@ WinReadLinkDirectory( */ offset = 0; -#ifdef UNICODE if (reparseBuffer->MountPointReparseBuffer.PathBuffer[0] == L'\\') { /* * Check whether this is a mounted volume. @@ -634,7 +633,6 @@ WinReadLinkDirectory( offset = 4; } } -#endif /* UNICODE */ Tcl_WinTCharToUtf((const TCHAR *) reparseBuffer->MountPointReparseBuffer.PathBuffer, @@ -809,7 +807,7 @@ tclWinDebugPanic( { #define TCL_MAX_WARN_LEN 1024 va_list argList; - char buf[TCL_MAX_WARN_LEN * TCL_UTF_MAX]; + char buf[TCL_MAX_WARN_LEN * 3]; WCHAR msgString[TCL_MAX_WARN_LEN]; va_start(argList, format); @@ -868,7 +866,7 @@ TclpFindExecutable( * ignore. */ { WCHAR wName[MAX_PATH]; - char name[MAX_PATH * TCL_UTF_MAX]; + char name[MAX_PATH * 3]; /* * Under Windows we ignore argv0, and return the path for the file used to @@ -876,20 +874,11 @@ TclpFindExecutable( */ if (argv0 == NULL) { +# undef Tcl_SetPanicProc Tcl_SetPanicProc(tclWinDebugPanic); } -#ifdef UNICODE GetModuleFileNameW(NULL, wName, MAX_PATH); -#else - GetModuleFileNameA(NULL, name, sizeof(name)); - - /* - * Convert to WCHAR to get out of ANSI codepage - */ - - MultiByteToWideChar(CP_ACP, 0, name, -1, wName, MAX_PATH); -#endif WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, sizeof(name), NULL, NULL); TclWinNoBackslash(name); TclSetObjNameOfExecutable(Tcl_NewStringObj(name, -1), NULL); @@ -942,10 +931,9 @@ TclpMatchInDirectory( * Match a single file directly. */ - int len; DWORD attr; WIN32_FILE_ATTRIBUTE_DATA data; - const char *str = Tcl_GetStringFromObj(norm,&len); + const char *str = TclGetString(norm); native = Tcl_FSGetNativePath(pathPtr); @@ -955,7 +943,7 @@ TclpMatchInDirectory( } attr = data.dwFileAttributes; - if (NativeMatchType(WinIsDrive(str,len), attr, native, types)) { + if (NativeMatchType(WinIsDrive(str,norm->length), attr, native, types)) { Tcl_ListObjAppendElement(interp, resultPtr, pathPtr); } } @@ -966,7 +954,7 @@ TclpMatchInDirectory( WIN32_FIND_DATA data; const char *dirName; /* UTF-8 dir name, later with pattern * appended. */ - int dirLength; + size_t dirLength; int matchSpecialDots; Tcl_DString ds; /* Native encoding of dir, also used * temporarily for other things. */ @@ -1005,7 +993,8 @@ TclpMatchInDirectory( */ Tcl_DStringInit(&dsOrig); - dirName = Tcl_GetStringFromObj(fileNamePtr, &dirLength); + dirName = TclGetString(fileNamePtr); + dirLength = fileNamePtr->length; Tcl_DStringAppend(&dsOrig, dirName, dirLength); lastChar = dirName[dirLength -1]; @@ -1183,7 +1172,7 @@ TclpMatchInDirectory( static int WinIsDrive( const char *name, /* Name (UTF-8) */ - int len) /* Length of name */ + size_t len) /* Length of name */ { int remove = 0; @@ -1460,9 +1449,9 @@ TclpGetUserHome( domain = Tcl_UtfFindFirst(name, '@'); if (domain == NULL) { const char *ptr; - + /* no domain - firstly check it's the current user */ - if ( (ptr = TclpGetUserName(&ds)) != NULL + if ( (ptr = TclpGetUserName(&ds)) != NULL && strcasecmp(name, ptr) == 0 ) { /* try safest and fastest way to get current user home */ @@ -1485,7 +1474,7 @@ TclpGetUserHome( Tcl_DStringInit(&ds); wName = Tcl_UtfToUniCharDString(name, nameLen, &ds); while (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) &uiPtr) != 0) { - /* + /* * user does not exists - if domain was not specified, * try again using current domain. */ @@ -1600,7 +1589,7 @@ NativeAccess( return 0; } - /* + /* * If it's not a directory (assume file), do several fast checks: */ if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { @@ -1654,7 +1643,6 @@ NativeAccess( * what permissions the OS has set for a file. */ -#ifdef UNICODE { SECURITY_DESCRIPTOR *sdPtr = NULL; unsigned long size; @@ -1817,7 +1805,6 @@ NativeAccess( } } -#endif /* !UNICODE */ return 0; } @@ -2031,7 +2018,7 @@ NativeStat( */ fileHandle = CreateFile(nativePath, GENERIC_READ, - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL); @@ -2765,15 +2752,14 @@ TclpObjNormalizePath( * Not the end of the string. */ - int len; char *path; Tcl_Obj *tmpPathPtr; tmpPathPtr = Tcl_NewStringObj(Tcl_DStringValue(&ds), nextCheckpoint); Tcl_AppendToObj(tmpPathPtr, lastValidPathEnd, -1); - path = Tcl_GetStringFromObj(tmpPathPtr, &len); - Tcl_SetStringObj(pathPtr, path, len); + path = TclGetString(tmpPathPtr); + Tcl_SetStringObj(pathPtr, path, tmpPathPtr->length); Tcl_DecrRefCount(tmpPathPtr); } else { /* @@ -2856,9 +2842,8 @@ TclWinVolumeRelativeNormalize( * also on drive C. */ - int cwdLen; - const char *drive = - Tcl_GetStringFromObj(useThisCwd, &cwdLen); + const char *drive = TclGetString(useThisCwd); + size_t cwdLen = useThisCwd->length; char drive_cur = path[0]; if (drive_cur >= 'a') { |