diff options
author | sebres <sebres@users.sourceforge.net> | 2018-05-28 12:26:20 (GMT) |
---|---|---|
committer | sebres <sebres@users.sourceforge.net> | 2018-05-28 12:26:20 (GMT) |
commit | 6966f0a2b1e1699483efc0f5b692224d10b07ab5 (patch) | |
tree | 696199c84cf337f30375afa3794afc98fba86b2e /win/tclWinInit.c | |
parent | 263de53394ce997af74f20135843ba8ef2e3b16e (diff) | |
parent | 89a84af271178d64a75a68b44f8434452fcba03e (diff) | |
download | tcl-6966f0a2b1e1699483efc0f5b692224d10b07ab5.zip tcl-6966f0a2b1e1699483efc0f5b692224d10b07ab5.tar.gz tcl-6966f0a2b1e1699483efc0f5b692224d10b07ab5.tar.bz2 |
merge 8.5 (conflicts resolved, rewritten without winapi-stubs)
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 98c7ed5..8e567e3 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -514,6 +514,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); +} + /* *--------------------------------------------------------------------------- * @@ -544,8 +565,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); @@ -623,15 +642,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); |