summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--win/tclWin32Dll.c8
-rw-r--r--win/tclWinInit.c13
-rw-r--r--win/tclWinInt.h3
4 files changed, 22 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 79a0301..edd9aed 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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-30 Daniel Steffen <das@users.sourceforge.net>
* generic/tclInt.h: add assert macros for clang static
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;