diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-05-29 07:23:51 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-05-29 07:23:51 (GMT) |
commit | bb503004b6169640fd3be00ab4c09d49368bdf42 (patch) | |
tree | 9e1d6c017847ea8cee4828c60e29253c602b1486 /win/tclWinInit.c | |
parent | 267cdaec036394312cd843ed142d998f7bbee4f3 (diff) | |
parent | a2ce3dab9b2939f21c06358081d0977ec937e106 (diff) | |
download | tcl-bb503004b6169640fd3be00ab4c09d49368bdf42.zip tcl-bb503004b6169640fd3be00ab4c09d49368bdf42.tar.gz tcl-bb503004b6169640fd3be00ab4c09d49368bdf42.tar.bz2 |
merge 8.6
Diffstat (limited to 'win/tclWinInit.c')
-rw-r--r-- | win/tclWinInit.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/win/tclWinInit.c b/win/tclWinInit.c index 91f149b..b77a580 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -503,6 +503,27 @@ Tcl_GetEncodingNameFromEnvironment( return Tcl_DStringValue(bufPtr); } +const char * +TclpGetUserName( + Tcl_DString *bufferPtr) /* Uninitialized or free DString filled with + * the name of user. */ +{ + Tcl_DStringInit(bufferPtr); + + if (TclGetEnv("USERNAME", bufferPtr) == NULL) { + TCHAR szUserName[UNLEN+1]; + DWORD cchUserNameLen = UNLEN; + + if (!GetUserName(szUserName, &cchUserNameLen)) { + return NULL; + } + cchUserNameLen--; + cchUserNameLen *= sizeof(TCHAR); + Tcl_WinTCharToUtf(szUserName, cchUserNameLen, bufferPtr); + } + return Tcl_DStringValue(bufferPtr); +} + /* *--------------------------------------------------------------------------- * @@ -533,8 +554,6 @@ TclpSetVariables( static OSVERSIONINFOW osInfo; static int osInfoInitialized = 0; Tcl_DString ds; - TCHAR szUserName[UNLEN+1]; - DWORD cchUserNameLen = UNLEN; Tcl_SetVar2Ex(interp, "tclDefaultLibrary", NULL, TclGetProcessGlobalValue(&defaultLibraryDir), TCL_GLOBAL_ONLY); @@ -609,15 +628,8 @@ TclpSetVariables( * Note: cchUserNameLen is number of characters including nul terminator. */ - Tcl_DStringInit(&ds); - if (TclGetEnv("USERNAME", &ds) == NULL) { - if (GetUserName(szUserName, &cchUserNameLen) != 0) { - int cbUserNameLen = cchUserNameLen - 1; - cbUserNameLen *= sizeof(TCHAR); - Tcl_WinTCharToUtf(szUserName, cbUserNameLen, &ds); - } - } - Tcl_SetVar2(interp, "tcl_platform", "user", Tcl_DStringValue(&ds), + ptr = TclpGetUserName(&ds); + Tcl_SetVar2(interp, "tcl_platform", "user", ptr ? ptr : "", TCL_GLOBAL_ONLY); Tcl_DStringFree(&ds); |