diff options
author | patthoyts <patthoyts@users.sourceforge.net> | 2009-07-01 14:05:19 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@users.sourceforge.net> | 2009-07-01 14:05:19 (GMT) |
commit | 32696239facf495e5bcf0d662143edb3009aef9e (patch) | |
tree | c20dca5e50b580b0e63ba33977a4558339a631bc /win/tclWinInit.c | |
parent | 3234624adfe748f3d9e906e52cd9935faa1a913a (diff) | |
download | tcl-32696239facf495e5bcf0d662143edb3009aef9e.zip tcl-32696239facf495e5bcf0d662143edb3009aef9e.tar.gz tcl-32696239facf495e5bcf0d662143edb3009aef9e.tar.bz2 |
Handle the GetUserName API call appropriately for wide/narrow versions. [Bug 2806622]
Diffstat (limited to 'win/tclWinInit.c')
-rw-r--r-- | win/tclWinInit.c | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/win/tclWinInit.c b/win/tclWinInit.c index f0c2a9e..2d923c1 100644 --- a/win/tclWinInit.c +++ b/win/tclWinInit.c @@ -10,7 +10,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinInit.c,v 1.75 2007/12/13 15:28:44 dgp Exp $ + * RCS: @(#) $Id: tclWinInit.c,v 1.75.2.1 2009/07/01 14:05:19 patthoyts Exp $ */ #include "tclWinInt.h" @@ -503,8 +503,8 @@ TclpSetVariables( OemId *oemId; OSVERSIONINFOA osInfo; Tcl_DString ds; - TCHAR szUserName[UNLEN+1]; - DWORD dwUserNameLen = sizeof(szUserName); + WCHAR szUserName[UNLEN+1]; + DWORD cchUserNameLen = UNLEN; Tcl_SetVar2Ex(interp, "tclDefaultLibrary", NULL, TclGetProcessGlobalValue(&defaultLibraryDir), TCL_GLOBAL_ONLY); @@ -573,12 +573,15 @@ TclpSetVariables( /* * Initialize the user name from the environment first, since this is much * faster than asking the system. + * Note: cchUserNameLen is number of characters including nul terminator. */ Tcl_DStringInit(&ds); if (TclGetEnv("USERNAME", &ds) == NULL) { - if (GetUserName(szUserName, &dwUserNameLen) != 0) { - Tcl_WinTCharToUtf(szUserName, (int) dwUserNameLen, &ds); + if (tclWinProcs->getUserName((LPTSTR)szUserName, &cchUserNameLen) != 0) { + int cbUserNameLen = cchUserNameLen - 1; + if (tclWinProcs->useWide) cbUserNameLen *= sizeof(WCHAR); + Tcl_WinTCharToUtf((LPTSTR)szUserName, cbUserNameLen, &ds); } } Tcl_SetVar2(interp, "tcl_platform", "user", Tcl_DStringValue(&ds), |