mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
os: another attempt to handle OpenFile flag parameter properly on Windows
Fixes #1791. R=rsc, r, r, iant CC=golang-dev https://golang.org/cl/4551046
This commit is contained in:
parent
2386808ee9
commit
cb96d98b06
2 changed files with 16 additions and 11 deletions
|
|
@ -918,7 +918,15 @@ func TestAppend(t *testing.T) {
|
||||||
}
|
}
|
||||||
s = writeFile(t, f, O_CREATE|O_APPEND|O_RDWR, "new&append")
|
s = writeFile(t, f, O_CREATE|O_APPEND|O_RDWR, "new&append")
|
||||||
if s != "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")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -230,16 +230,13 @@ func Open(path string, mode int, perm uint32) (fd int, errno int) {
|
||||||
}
|
}
|
||||||
var createmode uint32
|
var createmode uint32
|
||||||
switch {
|
switch {
|
||||||
case mode&O_CREAT != 0:
|
case mode&(O_CREAT|O_EXCL) == (O_CREAT | O_EXCL):
|
||||||
switch {
|
createmode = CREATE_NEW
|
||||||
case mode&O_EXCL != 0:
|
case mode&(O_CREAT|O_TRUNC) == (O_CREAT | O_TRUNC):
|
||||||
createmode = CREATE_NEW
|
createmode = CREATE_ALWAYS
|
||||||
case mode&O_APPEND != 0:
|
case mode&O_CREAT == O_CREAT:
|
||||||
createmode = OPEN_ALWAYS
|
createmode = OPEN_ALWAYS
|
||||||
default:
|
case mode&O_TRUNC == O_TRUNC:
|
||||||
createmode = CREATE_ALWAYS
|
|
||||||
}
|
|
||||||
case mode&O_TRUNC != 0:
|
|
||||||
createmode = TRUNCATE_EXISTING
|
createmode = TRUNCATE_EXISTING
|
||||||
default:
|
default:
|
||||||
createmode = OPEN_EXISTING
|
createmode = OPEN_EXISTING
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue