diff options
author | patthoyts <patthoyts@users.sourceforge.net> | 2009-07-01 14:38:05 (GMT) |
---|---|---|
committer | patthoyts <patthoyts@users.sourceforge.net> | 2009-07-01 14:38:05 (GMT) |
commit | 910e24fb04f5006fb5f14730497c27c89c1d83fb (patch) | |
tree | a9abcd3ce1092bfcf43664342b0cb6085a703ff1 /win | |
parent | 0df2c997699d7473522308e26a99742d375548d2 (diff) | |
download | tcl-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')
-rw-r--r-- | win/tclWin32Dll.c | 8 | ||||
-rw-r--r-- | win/tclWinInit.c | 13 | ||||
-rw-r--r-- | win/tclWinInt.h | 3 |
3 files changed, 15 insertions, 9 deletions
diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 8b7387f..eb50cb1 100644 --- a/win/tclWin32Dll.c +++ b/win/tclWin32Dll.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: tclWin32Dll.c,v 1.58 2008/10/26 18:43:26 dkf Exp $ + * RCS: @(#) $Id: tclWin32Dll.c,v 1.59 2009/07/01 14:38:07 patthoyts Exp $ */ #include "tclWinInt.h" @@ -124,7 +124,8 @@ static TclWinProcs asciiProcs = { NULL, NULL, NULL, NULL, NULL, NULL, /* ReadConsole and WriteConsole */ (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleA, - (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleA + (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleA, + (BOOL (WINAPI *)(LPTSTR, LPDWORD)) GetUserNameA }; static TclWinProcs unicodeProcs = { @@ -182,7 +183,8 @@ static TclWinProcs unicodeProcs = { NULL, NULL, NULL, NULL, NULL, NULL, /* ReadConsole and WriteConsole */ (BOOL (WINAPI *)(HANDLE, LPVOID, DWORD, LPDWORD, LPVOID)) ReadConsoleW, - (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleW + (BOOL (WINAPI *)(HANDLE, const void*, DWORD, LPDWORD, LPVOID)) WriteConsoleW, + (BOOL (WINAPI *)(LPTSTR, LPDWORD))GetUserNameW }; TclWinProcs *tclWinProcs; 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), diff --git a/win/tclWinInt.h b/win/tclWinInt.h index 0843bf1..546cf17 100644 --- a/win/tclWinInt.h +++ b/win/tclWinInt.h @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinInt.h,v 1.30 2008/05/02 10:27:08 dkf Exp $ + * RCS: @(#) $Id: tclWinInt.h,v 1.31 2009/07/01 14:38:08 patthoyts Exp $ */ #ifndef _TCLWININT @@ -144,6 +144,7 @@ typedef struct TclWinProcs { LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved ); + BOOL (WINAPI *getUserName)(LPTSTR lpBuffer, LPDWORD lpnSize); } TclWinProcs; MODULE_SCOPE TclWinProcs *tclWinProcs; |