1
0
mirror of https://github.com/golang/go synced 2024-11-25 07:27:57 -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:
Alex Brainman 2011-04-22 15:31:25 +10:00
parent 8d6a12f570
commit 59c18b0b36
2 changed files with 17 additions and 2 deletions

View File

@ -886,6 +886,18 @@ func TestAppend(t *testing.T) {
if s != "new|append" { if s != "new|append" {
t.Fatalf("writeFile: have %q want %q", 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) { func TestStatDirWithTrailingSlash(t *testing.T) {

View File

@ -220,9 +220,12 @@ 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 != 0:
if mode&O_EXCL != 0 { switch {
case mode&O_EXCL != 0:
createmode = CREATE_NEW createmode = CREATE_NEW
} else { case mode&O_APPEND != 0:
createmode = OPEN_ALWAYS
default:
createmode = CREATE_ALWAYS createmode = CREATE_ALWAYS
} }
case mode&O_TRUNC != 0: case mode&O_TRUNC != 0: