diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-04 12:53:25 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2019-12-04 12:53:25 (GMT) |
commit | d02ab64fa21f394ed414f13f1670cf3661fae3a7 (patch) | |
tree | a783c8f58787d43253776ae6493efa496ba46fb0 /win/tclWinFile.c | |
parent | 40938f72a284ade073ef88ce65725422bdb1073a (diff) | |
download | tcl-d02ab64fa21f394ed414f13f1670cf3661fae3a7.zip tcl-d02ab64fa21f394ed414f13f1670cf3661fae3a7.tar.gz tcl-d02ab64fa21f394ed414f13f1670cf3661fae3a7.tar.bz2 |
Use the right encoding when converting (Unicode) messages regarding socket errors on Windows. Some code cleanup in win/tclWinfile.c.
Diffstat (limited to 'win/tclWinFile.c')
-rw-r--r-- | win/tclWinFile.c | 69 |
1 files changed, 32 insertions, 37 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c index e050862..752aa0c 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -169,7 +169,7 @@ static int NativeWriteReparse(const WCHAR *LinkDirectory, REPARSE_DATA_BUFFER *buffer); static int NativeMatchType(int isDrive, DWORD attr, const WCHAR *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 WCHAR *LinkSource); static Tcl_Obj * WinReadLinkDirectory(const WCHAR *LinkDirectory); @@ -395,11 +395,11 @@ WinSymLinkDirectory( */ for (loop = nativeTarget; *loop != 0; loop++) { - if (*loop == L'/') { - *loop = L'\\'; + if (*loop == '/') { + *loop = '\\'; } } - if ((nativeTarget[len-1] == L'\\') && (nativeTarget[len-2] != L':')) { + if ((nativeTarget[len-1] == '\\') && (nativeTarget[len-2] != ':')) { nativeTarget[len-1] = 0; } @@ -572,8 +572,7 @@ WinReadLinkDirectory( */ offset = 0; -#if 1 - if (reparseBuffer->MountPointReparseBuffer.PathBuffer[0] == L'\\') { + if (reparseBuffer->MountPointReparseBuffer.PathBuffer[0] == '\\') { /* * Check whether this is a mounted volume. */ @@ -587,7 +586,7 @@ WinReadLinkDirectory( * to fix here. It doesn't seem very well documented. */ - reparseBuffer->MountPointReparseBuffer.PathBuffer[1]=L'\\'; + reparseBuffer->MountPointReparseBuffer.PathBuffer[1] = '\\'; /* * Check if a corresponding drive letter exists, and use that @@ -634,11 +633,10 @@ WinReadLinkDirectory( offset = 4; } } -#endif /* UNICODE */ Tcl_WinTCharToUtf((TCHAR *) reparseBuffer->MountPointReparseBuffer.PathBuffer, - (int) reparseBuffer->MountPointReparseBuffer + reparseBuffer->MountPointReparseBuffer .SubstituteNameLength, &ds); copy = Tcl_DStringValue(&ds)+offset; @@ -810,13 +808,13 @@ 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); vsnprintf(buf, sizeof(buf), format, argList); - msgString[TCL_MAX_WARN_LEN-1] = L'\0'; + msgString[TCL_MAX_WARN_LEN-1] = '\0'; MultiByteToWideChar(CP_UTF8, 0, buf, -1, msgString, TCL_MAX_WARN_LEN); /* @@ -824,7 +822,7 @@ tclWinDebugPanic( * and cause possible oversized window error. */ - if (msgString[TCL_MAX_WARN_LEN-1] != L'\0') { + if (msgString[TCL_MAX_WARN_LEN-1] != '\0') { memcpy(msgString + (TCL_MAX_WARN_LEN - 5), L" ...", 5 * sizeof(WCHAR)); } if (IsDebuggerPresent()) { @@ -869,7 +867,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 @@ -1174,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; @@ -1471,14 +1469,12 @@ TclpGetUserHome( } Tcl_DStringFree(&ds); } else { - Tcl_DStringInit(&ds); wName = (WCHAR *)Tcl_WinUtfToTChar(domain + 1, -1, &ds); rc = NetGetDCName(NULL, wName, (LPBYTE *) &wDomain); Tcl_DStringFree(&ds); nameLen = domain - name; } if (rc == 0) { - Tcl_DStringInit(&ds); wName = (WCHAR *)Tcl_WinUtfToTChar(name, nameLen, &ds); while (NetUserGetInfo(wDomain, wName, 1, (LPBYTE *) &uiPtr) != 0) { /* @@ -1505,7 +1501,7 @@ TclpGetUserHome( DWORD i, size = MAX_PATH; wHomeDir = uiPtr->usri1_home_dir; - if ((wHomeDir != NULL) && (wHomeDir[0] != L'\0')) { + if ((wHomeDir != NULL) && (wHomeDir[0] != '\0')) { size = lstrlenW(wHomeDir); Tcl_WinTCharToUtf((TCHAR *)wHomeDir, size*sizeof(WCHAR), bufferPtr); } else { @@ -1522,7 +1518,7 @@ TclpGetUserHome( result = Tcl_DStringValue(bufferPtr); /* - * Be sure we returns normalized path + * Be sure we return normalized path */ for (i = 0; i < size; ++i) { @@ -1691,7 +1687,6 @@ NativeAccess( * what permissions the OS has set for a file. */ -#if 1 { SECURITY_DESCRIPTOR *sdPtr = NULL; unsigned long size; @@ -1854,7 +1849,6 @@ NativeAccess( } } -#endif /* !UNICODE */ return 0; } @@ -1887,11 +1881,11 @@ NativeIsExec( } path += len-3; - if ((wcsicmp(path, L"exe") == 0) - || (wcsicmp(path, L"com") == 0) - || (wcsicmp(path, L"cmd") == 0) - || (wcsicmp(path, L"cmd") == 0) - || (wcsicmp(path, L"bat") == 0)) { + if ((_wcsicmp(path, L"exe") == 0) + || (_wcsicmp(path, L"com") == 0) + || (_wcsicmp(path, L"cmd") == 0) + || (_wcsicmp(path, L"cmd") == 0) + || (_wcsicmp(path, L"bat") == 0)) { return 1; } return 0; @@ -2205,7 +2199,7 @@ NativeDev( p = strchr(p + 1, '\\'); if (p == NULL) { /* - * Add terminating backslash to fullpath or GetVolumeInformationW() + * Add terminating backslash to fullpath or GetVolumeInformation() * won't work. */ @@ -2538,8 +2532,9 @@ TclpFilesystemPathType( int TclpObjNormalizePath( Tcl_Interp *interp, - Tcl_Obj *pathPtr, - int nextCheckpoint) + Tcl_Obj *pathPtr, /* An unshared object containing the path to + * normalize */ + int nextCheckpoint) /* offset to start at in pathPtr */ { char *lastValidPathEnd = NULL; Tcl_DString dsNorm; /* This will hold the normalized string. */ @@ -2586,8 +2581,8 @@ TclpObjNormalizePath( for (i=0 ; i<len ; i++) { WCHAR wc = ((WCHAR *) nativePath)[i]; - if (wc >= L'a') { - wc -= (L'a' - L'A'); + if (wc >= 'a') { + wc -= ('a' - 'A'); ((WCHAR *) nativePath)[i] = wc; } } @@ -2677,8 +2672,8 @@ TclpObjNormalizePath( if (isDrive) { WCHAR drive = ((WCHAR *) nativePath)[0]; - if (drive >= L'a') { - drive -= (L'a' - L'A'); + if (drive >= 'a') { + drive -= ('a' - 'A'); ((WCHAR *) nativePath)[0] = drive; } Tcl_DStringAppend(&dsNorm, (const char *)nativePath, @@ -2709,7 +2704,7 @@ TclpObjNormalizePath( Tcl_DStringAppend(&dsNorm, ((const char *)nativePath) + Tcl_DStringLength(&ds) - (dotLen * sizeof(WCHAR)), - (int)(dotLen * sizeof(WCHAR))); + dotLen * sizeof(WCHAR)); } else { /* * Normal path. @@ -2775,8 +2770,8 @@ TclpObjNormalizePath( * We have to make the drive letter uppercase. */ - if (wpath[0] >= L'a') { - wpath[0] -= (L'a' - L'A'); + if (wpath[0] >= 'a') { + wpath[0] -= ('a' - 'A'); } Tcl_DStringAppend(&dsNorm, (const char *) wpath, wpathlen * sizeof(WCHAR)); @@ -3021,7 +3016,7 @@ TclpNativeToNormalized( * The nativePath representation. * * Side effects: - * Memory will be allocated. The path may need to be normalized. + * Memory will be allocated. The path might be normalized. * *--------------------------------------------------------------------------- */ @@ -3073,7 +3068,7 @@ TclNativeCreateNativeRep( str = Tcl_GetString(validPathPtr); len = validPathPtr->length; - if (strlen(str) != (unsigned int) len) { + if (strlen(str) != len) { /* * String contains NUL-bytes. This is invalid. */ |