mirror of
https://github.com/golang/go
synced 2024-11-22 01:24:42 -07:00
os: Open with O_APPEND|O_CREATE to append to the end of file on Windows
Credit for the fix goes to Hector, test by PeterGo. Fixes #1655. R=golang-dev, rsc1, peterGo CC=golang-dev, hector https://golang.org/cl/4436051
This commit is contained in:
parent
8d6a12f570
commit
59c18b0b36
@ -886,6 +886,18 @@ func TestAppend(t *testing.T) {
|
||||
if s != "new|append" {
|
||||
t.Fatalf("writeFile: have %q want %q", s, "new|append")
|
||||
}
|
||||
s = writeFile(t, f, O_CREATE|O_APPEND|O_RDWR, "|append")
|
||||
if s != "new|append|append" {
|
||||
t.Fatalf("writeFile: have %q want %q", s, "new|append|append")
|
||||
}
|
||||
err := Remove(f)
|
||||
if err != nil {
|
||||
t.Fatalf("Remove: %v", err)
|
||||
}
|
||||
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")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatDirWithTrailingSlash(t *testing.T) {
|
||||
|
@ -220,9 +220,12 @@ func Open(path string, mode int, perm uint32) (fd int, errno int) {
|
||||
var createmode uint32
|
||||
switch {
|
||||
case mode&O_CREAT != 0:
|
||||
if mode&O_EXCL != 0 {
|
||||
switch {
|
||||
case mode&O_EXCL != 0:
|
||||
createmode = CREATE_NEW
|
||||
} else {
|
||||
case mode&O_APPEND != 0:
|
||||
createmode = OPEN_ALWAYS
|
||||
default:
|
||||
createmode = CREATE_ALWAYS
|
||||
}
|
||||
case mode&O_TRUNC != 0:
|
||||
|
Loading…
Reference in New Issue
Block a user