summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--generic/tclBasic.c4
-rw-r--r--generic/tclClock.c51
-rw-r--r--generic/tclIOUtil.c9
-rw-r--r--generic/tclZipfs.c21
-rw-r--r--library/clock.tcl3
-rw-r--r--unix/Makefile.in1
-rw-r--r--unix/tclUnixFile.c4
-rw-r--r--unix/tclUnixPort.h2
-rw-r--r--win/tclWinFile.c2
-rw-r--r--win/tclWinInit.c8
10 files changed, 69 insertions, 36 deletions
diff --git a/generic/tclBasic.c b/generic/tclBasic.c
index 92d0ed4..b90e12d 100644
--- a/generic/tclBasic.c
+++ b/generic/tclBasic.c
@@ -744,6 +744,10 @@ Tcl_CreateInterp(void)
Tcl_InitHashTable(&iPtr->packageTable, TCL_STRING_KEYS);
iPtr->packageUnknown = NULL;
+#ifdef _WIN32
+# define getenv(x) _wgetenv(L##x) /* On Windows, use _wgetenv below */
+#endif
+
/* TIP #268 */
#if (TCL_RELEASE_LEVEL == TCL_FINAL_RELEASE)
if (getenv("TCL_PKG_PREFER_LATEST") == NULL) {
diff --git a/generic/tclClock.c b/generic/tclClock.c
index 8cb1b40..bcc5256 100644
--- a/generic/tclClock.c
+++ b/generic/tclClock.c
@@ -1650,19 +1650,37 @@ ClockGetenvObjCmd(
int objc,
Tcl_Obj *const objv[])
{
+#ifdef _WIN32
+ const WCHAR *varName;
+ const WCHAR *varValue;
+ Tcl_DString ds;
+#else
const char *varName;
const char *varValue;
+#endif
if (objc != 2) {
Tcl_WrongNumArgs(interp, 1, objv, "name");
return TCL_ERROR;
}
+#ifdef _WIN32
+ Tcl_DStringInit(&ds);
+ varName = Tcl_UtfToWCharDString(TclGetString(objv[1]), -1, &ds);
+ varValue = _wgetenv(varName);
+ if (varValue == NULL) {
+ Tcl_DStringFree(&ds);
+ } else {
+ Tcl_DStringSetLength(&ds, 0);
+ Tcl_WCharToUtfDString(varValue, -1, &ds);
+ Tcl_DStringResult(interp, &ds);
+ }
+#else
varName = TclGetString(objv[1]);
varValue = getenv(varName);
- if (varValue == NULL) {
- varValue = "";
+ if (varValue != NULL) {
+ Tcl_SetObjResult(interp, Tcl_NewStringObj(varValue, -1));
}
- Tcl_SetObjResult(interp, Tcl_NewStringObj(varValue, -1));
+#endif
return TCL_OK;
}
@@ -2021,15 +2039,24 @@ ClockSecondsObjCmd(
*----------------------------------------------------------------------
*/
+#ifdef _WIN32
+#define getenv(x) _wgetenv(L##x)
+#else
+#define WCHAR char
+#define wcslen strlen
+#define wcscmp strcmp
+#define wcscpy strcpy
+#endif
+
static void
TzsetIfNecessary(void)
{
- static char *tzWas = (char *)INT2PTR(-1); /* Previous value of TZ, protected by
- * clockMutex. */
+ static WCHAR* tzWas = (WCHAR *)INT2PTR(-1); /* Previous value of TZ, protected by
+ * clockMutex. */
static long tzLastRefresh = 0; /* Used for latency before next refresh */
static size_t tzEnvEpoch = 0; /* Last env epoch, for faster signaling,
that TZ changed via TCL */
- const char *tzIsNow; /* Current value of TZ */
+ const WCHAR *tzIsNow; /* Current value of TZ */
/*
* Prevent performance regression on some platforms by resolving of system time zone:
@@ -2047,17 +2074,17 @@ TzsetIfNecessary(void)
Tcl_MutexLock(&clockMutex);
tzIsNow = getenv("TZ");
- if (tzIsNow != NULL && (tzWas == NULL || tzWas == INT2PTR(-1)
- || strcmp(tzIsNow, tzWas) != 0)) {
+ if (tzIsNow != NULL && (tzWas == NULL || tzWas == (WCHAR *)INT2PTR(-1)
+ || wcscmp(tzIsNow, tzWas) != 0)) {
tzset();
- if (tzWas != NULL && tzWas != INT2PTR(-1)) {
+ if (tzWas != NULL && tzWas != (WCHAR *)INT2PTR(-1)) {
Tcl_Free(tzWas);
}
- tzWas = (char *)Tcl_Alloc(strlen(tzIsNow) + 1);
- strcpy(tzWas, tzIsNow);
+ tzWas = (WCHAR *)Tcl_Alloc(sizeof(WCHAR) * (wcslen(tzIsNow) + 1));
+ wcscpy(tzWas, tzIsNow);
} else if (tzIsNow == NULL && tzWas != NULL) {
tzset();
- if (tzWas != INT2PTR(-1)) Tcl_Free(tzWas);
+ if (tzWas != (WCHAR *)INT2PTR(-1)) Tcl_Free(tzWas);
tzWas = NULL;
}
Tcl_MutexUnlock(&clockMutex);
diff --git a/generic/tclIOUtil.c b/generic/tclIOUtil.c
index 2c911a1..f433781 100644
--- a/generic/tclIOUtil.c
+++ b/generic/tclIOUtil.c
@@ -3078,6 +3078,13 @@ Tcl_FSLoadFile(
*
*/
+#ifdef _WIN32
+#define getenv(x) _wgetenv(L##x)
+#define atoi(x) _wtoi(x)
+#else
+#define WCHAR char
+#endif
+
static int
skipUnlink(
Tcl_Obj *shlibFile)
@@ -3099,7 +3106,7 @@ skipUnlink(
(void)shlibFile;
return 1;
#else
- char *skipstr = getenv("TCL_TEMPLOAD_NO_UNLINK");
+ WCHAR *skipstr = getenv("TCL_TEMPLOAD_NO_UNLINK");
if (skipstr && (skipstr[0] != '\0')) {
return atoi(skipstr);
diff --git a/generic/tclZipfs.c b/generic/tclZipfs.c
index 4505827..9c94851 100644
--- a/generic/tclZipfs.c
+++ b/generic/tclZipfs.c
@@ -3090,16 +3090,13 @@ ZipFSListObjCmd(
*-------------------------------------------------------------------------
*/
-#ifdef _WIN32
-#define LIBRARY_SIZE 64
-#endif /* _WIN32 */
-
Tcl_Obj *
TclZipfs_TclLibrary(void)
{
Tcl_Obj *vfsInitScript;
int found;
-#if defined(_WIN32) && !defined(STATIC_BUILD)
+#if (defined(_WIN32) || defined(__CYGWIN__)) && !defined(STATIC_BUILD)
+# define LIBRARY_SIZE 64
HMODULE hModule;
WCHAR wName[MAX_PATH + LIBRARY_SIZE];
char dllName[(MAX_PATH + LIBRARY_SIZE) * 3];
@@ -3134,22 +3131,20 @@ TclZipfs_TclLibrary(void)
*/
#if !defined(STATIC_BUILD)
-#if defined(_WIN32)
+#if defined(_WIN32) || defined(__CYGWIN__)
hModule = (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/library/clock.tcl b/library/clock.tcl
index 150ae3c..136ded2 100644
--- a/library/clock.tcl
+++ b/library/clock.tcl
@@ -2988,8 +2988,7 @@ proc ::tcl::clock::GetSystemTimeZone {} {
set timezone $result
} elseif {[set result [getenv TZ]] ne {}} {
set timezone $result
- }
- if {![info exists timezone]} {
+ } else {
# Cache the time zone only if it was detected by one of the
# expensive methods.
if { [info exists CachedSystemTimeZone] } {
diff --git a/unix/Makefile.in b/unix/Makefile.in
index c950719..54fcf64 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 3c8a318..05876a8 100644
--- a/unix/tclUnixFile.c
+++ b/unix/tclUnixFile.c
@@ -44,8 +44,8 @@ TclpFindExecutable(
wchar_t buf[PATH_MAX];
char name[PATH_MAX * 3 + 1];
- GetModuleFileNameW(NULL, buf, PATH_MAX);
- cygwin_conv_path(3, buf, name, PATH_MAX);
+ GetModuleFileNameW(NULL, buf, sizeof(buf)/sizeof(wchar_t));
+ 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/unix/tclUnixPort.h b/unix/tclUnixPort.h
index cefe603..4027f1f 100644
--- a/unix/tclUnixPort.h
+++ b/unix/tclUnixPort.h
@@ -92,6 +92,8 @@ extern "C" {
/* Make some symbols available without including <windows.h> */
# define CP_UTF8 65001
# define GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS 0x00000004
+# define HMODULE void *
+# define MAX_PATH 260
# define SOCKET unsigned int
# define WSAEWOULDBLOCK 10035
typedef unsigned short WCHAR;
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index f954516..676ae38 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -866,7 +866,7 @@ TclpFindExecutable(
char name[MAX_PATH * 3];
(void)argv0;
- GetModuleFileNameW(NULL, wName, MAX_PATH);
+ GetModuleFileNameW(NULL, wName, sizeof(wName)/sizeof(WCHAR));
WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, sizeof(name), NULL, NULL);
TclWinNoBackslash(name);
TclSetObjNameOfExecutable(Tcl_NewStringObj(name, -1), NULL);
diff --git a/win/tclWinInit.c b/win/tclWinInit.c
index 7205498..5817377 100644
--- a/win/tclWinInit.c
+++ b/win/tclWinInit.c
@@ -334,8 +334,8 @@ InitializeDefaultLibraryDir(
char name[(MAX_PATH + LIBRARY_SIZE) * 3];
char *end, *p;
- GetModuleFileNameW(hModule, wName, MAX_PATH);
- WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, MAX_PATH * 3, NULL, NULL);
+ GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR));
+ WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, sizeof(name), NULL, NULL);
end = strrchr(name, '\\');
*end = '\0';
@@ -382,8 +382,8 @@ InitializeSourceLibraryDir(
char name[(MAX_PATH + LIBRARY_SIZE) * 3];
char *end, *p;
- GetModuleFileNameW(hModule, wName, MAX_PATH);
- WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, MAX_PATH * 3, NULL, NULL);
+ GetModuleFileNameW(hModule, wName, sizeof(wName)/sizeof(WCHAR));
+ WideCharToMultiByte(CP_UTF8, 0, wName, -1, name, sizeof(name), NULL, NULL);
end = strrchr(name, '\\');
*end = '\0';