summaryrefslogtreecommitdiffstats
path: root/win/tclWinFile.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2015-10-06 14:49:23 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2015-10-06 14:49:23 (GMT)
commit2738bd34505c7fa7a1d68fe8f5bbaa2f5d35c12c (patch)
tree0f4f9046805988cc273ce06b3db5fd75c8167c21 /win/tclWinFile.c
parente38804664b6a2b090714657b23bcfe211c58347c (diff)
parent40ba2e067496a7fab51129617bbcd0f5553f285f (diff)
downloadtcl-2738bd34505c7fa7a1d68fe8f5bbaa2f5d35c12c.zip
tcl-2738bd34505c7fa7a1d68fe8f5bbaa2f5d35c12c.tar.gz
tcl-2738bd34505c7fa7a1d68fe8f5bbaa2f5d35c12c.tar.bz2
Fix [b42a851475]: file normalize ~user returns wrong directory on Windows
Diffstat (limited to 'win/tclWinFile.c')
-rwxr-xr-xwin/tclWinFile.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index f6e3a4b..be9c947 100755
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -17,7 +17,11 @@
#include <winioctl.h>
#include <shlobj.h>
#include <lm.h> /* For TclpGetUserHome(). */
+#include <userenv.h> /* For TclpGetUserHome(). */
+#ifdef _MSC_VER
+# pragma comment(lib, "userenv.lib")
+#endif
/*
* The number of 100-ns intervals between the Windows system epoch (1601-01-01
* on the proleptic Gregorian calendar) and the Posix epoch (1970-01-01).
@@ -1461,12 +1465,17 @@ TclpGetUserHome(
} else {
/*
* User exists but has no home dir. Return
- * "{Windows Drive}:/users/default".
+ * "{GetProfilesDirectory}/<user>".
*/
-
- GetWindowsDirectoryW(buf, MAX_PATH);
- Tcl_UniCharToUtfDString(buf, 2, bufferPtr);
- TclDStringAppendLiteral(bufferPtr, "/users/default");
+ DWORD size = MAX_PATH;
+ int i;
+ GetProfilesDirectoryW(buf, &size);
+ for (i = 0; i < size; ++i){
+ if (buf[i] == '\\') buf[i] = '/';
+ }
+ Tcl_UniCharToUtfDString(buf, size-1, bufferPtr);
+ Tcl_DStringAppend(bufferPtr, "/", -1);
+ Tcl_DStringAppend(bufferPtr, name, -1);
}
result = Tcl_DStringValue(bufferPtr);
NetApiBufferFree((void *) uiPtr);