diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-02-23 07:42:14 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2021-02-23 07:42:14 (GMT) |
commit | 92eff9a92206e2292cbd5dbc8e2320ce874ea7fb (patch) | |
tree | 15ef703a6d84d5fca9cca7fb367e8a0c0977e503 /generic/tclClock.c | |
parent | 8512e037c283c963896ccc29a5118e64a9b5e830 (diff) | |
parent | eb9f949b2cfdc79e6a450a1e4f6e3580ccde4d9f (diff) | |
download | tcl-92eff9a92206e2292cbd5dbc8e2320ce874ea7fb.zip tcl-92eff9a92206e2292cbd5dbc8e2320ce874ea7fb.tar.gz tcl-92eff9a92206e2292cbd5dbc8e2320ce874ea7fb.tar.bz2 |
Merge 8.7
Diffstat (limited to 'generic/tclClock.c')
-rw-r--r-- | generic/tclClock.c | 51 |
1 files changed, 39 insertions, 12 deletions
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); |