summaryrefslogtreecommitdiffstats
path: root/win/tclWinInit.c
diff options
context:
space:
mode:
authorpatthoyts <patthoyts@users.sourceforge.net>2009-07-01 14:38:05 (GMT)
committerpatthoyts <patthoyts@users.sourceforge.net>2009-07-01 14:38:05 (GMT)
commit910e24fb04f5006fb5f14730497c27c89c1d83fb (patch)
treea9abcd3ce1092bfcf43664342b0cb6085a703ff1 /win/tclWinInit.c
parent0df2c997699d7473522308e26a99742d375548d2 (diff)
downloadtcl-910e24fb04f5006fb5f14730497c27c89c1d83fb.zip
tcl-910e24fb04f5006fb5f14730497c27c89c1d83fb.tar.gz
tcl-910e24fb04f5006fb5f14730497c27c89c1d83fb.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.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/win/tclWinInit.c b/win/tclWinInit.c
index 1d348a7..8d709e9 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.81 2009/02/03 23:10:57 nijtmans Exp $
+ * RCS: @(#) $Id: tclWinInit.c,v 1.82 2009/07/01 14:38:07 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),