From 4a83f77ba9ac5d498e841d925a930391543879b9 Mon Sep 17 00:00:00 2001
From: "jan.nijtmans" <nijtmans@users.sourceforge.net>
Date: Tue, 11 Oct 2011 13:19:54 +0000
Subject: [Bug 2935503] Incorrect mode field returned by file stat command

---
 ChangeLog        | 5 +++++
 tests/io.test    | 6 +++---
 win/tclWinFile.c | 6 +++---
 3 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 2af5dd6..7ecbfa4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2011-10-11  Jan Nijtmans  <nijtmans@users.sf.net>
+
+	* win/tclWinFile.c:    [Bug 2935503] Incorrect mode field
+	* tests/io.test:       returned by file stat command
+
 2011-10-07  Jan Nijtmans  <nijtmans@users.sf.net>
 
 	* win/tclWinChan.c:    Fix various gcc warnings
diff --git a/tests/io.test b/tests/io.test
index ed2619a..6029f18 100644
--- a/tests/io.test
+++ b/tests/io.test
@@ -5228,9 +5228,9 @@ test io-40.1 {POSIX open access modes: RDWR} {
     close $f
     set x
 } {zzy abzzy}
-test io-40.2 {POSIX open access modes: CREAT} {unixOnly} {
+test io-40.2 {POSIX open access modes: CREAT} {
     file delete $path(test3)
-    set f [open $path(test3) {WRONLY CREAT} 0600]
+    set f [open $path(test3) {WRONLY CREAT} 0666]
     file stat $path(test3) stats
     set x [format "0%o" [expr $stats(mode)&0777]]
     puts $f "line 1"
@@ -5239,7 +5239,7 @@ test io-40.2 {POSIX open access modes: CREAT} {unixOnly} {
     lappend x [gets $f]
     close $f
     set x
-} {0600 {line 1}}
+} {0666 {line 1}}
 
 # some tests can only be run is umask is 2
 # if "umask" cannot be run, the tests will be skipped.
diff --git a/win/tclWinFile.c b/win/tclWinFile.c
index 316a827..c98c42c 100644
--- a/win/tclWinFile.c
+++ b/win/tclWinFile.c
@@ -1074,7 +1074,7 @@ static int WinIsReserved(
  * volume, because for NTFS root volumes, the getFileAttributesProc
  * returns a 'hidden' attribute when it should not.
  * 
- * We never make any calss to a 'get attributes' routine here,
+ * We never make any calls to a 'get attributes' routine here,
  * since we have arranged things so that our caller already knows
  * such information.
  * 
@@ -2023,8 +2023,8 @@ NativeStatMode(DWORD attr, int checkLinks, int isExec)
      * other positions.
      */
 
-    mode |= (mode & 0x0700) >> 3;
-    mode |= (mode & 0x0700) >> 6;
+    mode |= (mode & (S_IREAD|S_IWRITE|S_IEXEC)) >> 3;
+    mode |= (mode & (S_IREAD|S_IWRITE|S_IEXEC)) >> 6;
     return (unsigned short)mode;
 }
 
-- 
cgit v0.12