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 | |
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]
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | win/tclWin32Dll.c | 8 | ||||
-rw-r--r-- | win/tclWinInit.c | 13 | ||||
-rw-r--r-- | win/tclWinInt.h | 3 |
4 files changed, 22 insertions, 9 deletions
@@ -1,3 +1,10 @@ +2009-07-01 Pat Thoyts <patthoyts@users.sourceforge.net> + + * win/tclWinInt.h: Handle the GetUserName API call via the + * win/tclWin32Dll.c: tclWinProcs indirection structure. This + * win/tclWinInit.c: fixes a problem obtaining the username when + the USERNAME environment variable is unset [Bug 2806622] + 2009-06-15 Don Porter <dgp@users.sourceforge.net> * generic/tclStringObj.c: sprintf() -> Tcl_ObjPrintf() conversion. diff --git a/win/tclWin32Dll.c b/win/tclWin32Dll.c index 9e6a0f0..eca7ec8 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.54 2007/12/13 15:28:43 dgp Exp $ + * RCS: @(#) $Id: tclWin32Dll.c,v 1.54.2.1 2009/07/01 14:05:19 patthoyts Exp $ */ #include "tclWinInt.h" @@ -134,7 +134,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 = { @@ -192,7 +193,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 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), diff --git a/win/tclWinInt.h b/win/tclWinInt.h index 40aa67c..f8471d8 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.29 2005/11/03 01:16:07 patthoyts Exp $ + * RCS: @(#) $Id: tclWinInt.h,v 1.29.10.1 2009/07/01 14:05:19 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; |