diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-06-14 18:31:24 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2018-06-14 18:31:24 (GMT) |
commit | 14994d8a856c6e59890aad6023793a6760c98e1a (patch) | |
tree | 1c5559c8ce5c44ad2f0275b5c0bc56d0c65cbab8 /win/tclWinInit.c | |
parent | 5e1789954df3a512ab8d71df2c60ffb6ea72b777 (diff) | |
parent | 919ec44584344d71c8ddad8d14d58adfdec28e8b (diff) | |
download | tcl-14994d8a856c6e59890aad6023793a6760c98e1a.zip tcl-14994d8a856c6e59890aad6023793a6760c98e1a.tar.gz tcl-14994d8a856c6e59890aad6023793a6760c98e1a.tar.bz2 |
Merge trunk. Some more size_t additions in parameters/fields
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 02fa674..e0fc73d 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); |