From 06ea55d820a91810fe57afda632449d0bca2fe52 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 23 Feb 2021 10:08:46 +0000 Subject: Simplify implementation on Cygwin: No need to use CFG_RUNTIME_BINDIR any more --- generic/tclZipfs.c | 16 +++++++--------- unix/Makefile.in | 1 - unix/tclUnixFile.c | 2 +- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c index f052c2e..4c668b0 100644 --- a/generic/tclZipfs.c +++ b/generic/tclZipfs.c @@ -3113,7 +3113,7 @@ TclZipfs_TclLibrary(void) { Tcl_Obj *vfsInitScript; int found; -#if defined(_WIN32) && !defined(STATIC_BUILD) +#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(STATIC_BUILD) HMODULE hModule; WCHAR wName[MAX_PATH + LIBRARY_SIZE]; char dllName[(MAX_PATH + LIBRARY_SIZE) * 3]; @@ -3148,22 +3148,20 @@ TclZipfs_TclLibrary(void) */ #if !defined(STATIC_BUILD) -#if defined(_WIN32) +#if defined(_WIN32) || defined(__CYGWIN__) hModule = TclWinGetTclInstance(); GetModuleFileNameW(hModule, wName, MAX_PATH); +#ifdef __CYGWIN__ + cygwin_conv_path(3, wName, dllName, sizeof(dllName)); +#else WideCharToMultiByte(CP_UTF8, 0, wName, -1, dllName, sizeof(dllName), NULL, NULL); +#endif if (ZipfsAppHookFindTclInit(dllName) == TCL_OK) { return Tcl_NewStringObj(zipfs_literal_tcl_library, -1); } #else - if (ZipfsAppHookFindTclInit( -#ifdef __CYGWIN__ - CFG_RUNTIME_BINDIR -#else - CFG_RUNTIME_LIBDIR -#endif - "/" CFG_RUNTIME_DLLFILE) == TCL_OK) { + if (ZipfsAppHookFindTclInit(CFG_RUNTIME_LIBDIR "/" CFG_RUNTIME_DLLFILE) == TCL_OK) { return Tcl_NewStringObj(zipfs_literal_tcl_library, -1); } #endif /* _WIN32 */ diff --git a/unix/Makefile.in b/unix/Makefile.in index 15d80cb..f885f5a 100644 --- a/unix/Makefile.in +++ b/unix/Makefile.in @@ -1523,7 +1523,6 @@ tclZipfs.o: $(GENERIC_DIR)/tclZipfs.c $(CC) -c $(CC_SWITCHES) \ -DCFG_RUNTIME_DLLFILE="\"$(TCL_LIB_FILE)\"" \ -DCFG_RUNTIME_LIBDIR="\"$(libdir)\"" \ - -DCFG_RUNTIME_BINDIR="\"$(bindir)\"" \ -I$(ZLIB_DIR) -I$(ZLIB_DIR)/contrib/minizip \ $(GENERIC_DIR)/tclZipfs.c diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 203a118..d72913b 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -45,7 +45,7 @@ TclpFindExecutable( char name[PATH_MAX * 3 + 1]; GetModuleFileNameW(NULL, buf, PATH_MAX); - cygwin_conv_path(3, buf, name, PATH_MAX); + cygwin_conv_path(3, buf, name, sizeof(name)); length = strlen(name); if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) { /* Strip '.exe' part. */ -- cgit v0.12 From c0f6db4b8165a139a30bd801ca3d8ffb56210940 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 23 Feb 2021 12:34:58 +0000 Subject: Revise buffer-sizes used in GetModuleFileNameW() calls. Available buffer-size reported to GetModuleFileNameW() was not always accurate --- unix/tclUnixFile.c | 6 +++--- win/tclWinFile.c | 2 +- win/tclWinInit.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/unix/tclUnixFile.c b/unix/tclUnixFile.c index 3b09799..f2a6b23 100644 --- a/unix/tclUnixFile.c +++ b/unix/tclUnixFile.c @@ -43,9 +43,9 @@ TclpFindExecutable( #ifdef __CYGWIN__ int length; char buf[PATH_MAX * 2]; - char name[PATH_MAX * TCL_UTF_MAX + 1]; - GetModuleFileNameW(NULL, buf, PATH_MAX); - cygwin_conv_path(3, buf, name, PATH_MAX); + char name[PATH_MAX * 3 + 1]; + GetModuleFileNameW(NULL, buf, sizeof(buf)/2); + cygwin_conv_path(3, buf, name, sizeof(name)); length = strlen(name); if ((length > 4) && !strcasecmp(name + length - 4, ".exe")) { /* Strip '.exe' part. */ diff --git a/win/tclWinFile.c b/win/tclWinFile.c index d582664..8df346f 100644 --- a/win/tclWinFile.c +++ b/win/tclWinFile.c @@ -852,7 +852,7 @@ TclpFindExecutable( * create this process. */ - if (GetModuleFileNameW(NULL, wName, MAX_PATH) == 0) { + if (GetModuleFileNameW(NULL, wName, sizeof(wName)/sizeof(WCHAR)) == 0) { GetModuleFileNameA(NULL, name, sizeof(name)); /* diff --git a/win/tclWinInit.c b/win/tclWinInit.c index 6c34573..2abcd3e 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -342,11 +342,11 @@ InitializeDefaultLibraryDir( { HMODULE hModule = TclWinGetTclInstance(); WCHAR wName[MAX_PATH + LIBRARY_SIZE]; - char name[(MAX_PATH + LIBRARY_SIZE) * TCL_UTF_MAX]; + char name[(MAX_PATH + LIBRARY_SIZE) * 3]; char *end, *p; - if (GetModuleFileNameW(hModule, wName, MAX_PATH) == 0) { - GetModuleFileNameA(hModule, name, MAX_PATH); + if (GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR)) == 0) { + GetModuleFileNameA(hModule, name, sizeof(name)); } else { ToUtf(wName, name); } @@ -393,11 +393,11 @@ InitializeSourceLibraryDir( { HMODULE hModule = TclWinGetTclInstance(); WCHAR wName[MAX_PATH + LIBRARY_SIZE]; - char name[(MAX_PATH + LIBRARY_SIZE) * TCL_UTF_MAX]; + char name[(MAX_PATH + LIBRARY_SIZE) * 3]; char *end, *p; - if (GetModuleFileNameW(hModule, wName, MAX_PATH) == 0) { - GetModuleFileNameA(hModule, name, MAX_PATH); + if (GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR)) == 0) { + GetModuleFileNameA(hModule, name, sizeof(name)); } else { ToUtf(wName, name); } -- cgit v0.12