]> Cypherpunks repositories - gostls13.git/commitdiff
os: another attempt to handle OpenFile flag parameter properly on Windows
authorAlex Brainman <alex.brainman@gmail.com>
Fri, 27 May 2011 07:02:24 +0000 (17:02 +1000)
committerAlex Brainman <alex.brainman@gmail.com>
Fri, 27 May 2011 07:02:24 +0000 (17:02 +1000)
Fixes #1791.

R=rsc, r, r, iant
CC=golang-dev
https://golang.org/cl/4551046

src/pkg/os/os_test.go
src/pkg/syscall/syscall_windows.go

index b146b92cf0e8a2b30fb7b875b142e268cf6f1c73..9a993cd6eda8bd3f3ca5eb2a6226067e6e3b4c17 100644 (file)
@@ -918,7 +918,15 @@ func TestAppend(t *testing.T) {
        }
        s = writeFile(t, f, O_CREATE|O_APPEND|O_RDWR, "new&append")
        if s != "new&append" {
-               t.Fatalf("writeFile: have %q want %q", s, "new&append")
+               t.Fatalf("writeFile: after append have %q want %q", s, "new&append")
+       }
+       s = writeFile(t, f, O_CREATE|O_RDWR, "old")
+       if s != "old&append" {
+               t.Fatalf("writeFile: after create have %q want %q", s, "old&append")
+       }
+       s = writeFile(t, f, O_CREATE|O_TRUNC|O_RDWR, "new")
+       if s != "new" {
+               t.Fatalf("writeFile: after truncate have %q want %q", s, "new")
        }
 }
 
index 6ba031faf877ffe1ead07f56c49623888b0871c2..37e90053e09092cae3c992b08c1a01d71a6e7a83 100644 (file)
@@ -230,16 +230,13 @@ func Open(path string, mode int, perm uint32) (fd int, errno int) {
        }
        var createmode uint32
        switch {
-       case mode&O_CREAT != 0:
-               switch {
-               case mode&O_EXCL != 0:
-                       createmode = CREATE_NEW
-               case mode&O_APPEND != 0:
-                       createmode = OPEN_ALWAYS
-               default:
-                       createmode = CREATE_ALWAYS
-               }
-       case mode&O_TRUNC != 0:
+       case mode&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL):
+               createmode = CREATE_NEW
+       case mode&(O_CREAT|O_TRUNC) == (O_CREAT | O_TRUNC):
+               createmode = CREATE_ALWAYS
+       case mode&O_CREAT == O_CREAT:
+               createmode = OPEN_ALWAYS
+       case mode&O_TRUNC == O_TRUNC:
                createmode = TRUNCATE_EXISTING
        default:
                createmode = OPEN_EXISTING