From: Akshat Kumar Date: Fri, 22 Feb 2013 22:06:25 +0000 (+0100) Subject: os: Plan 9: avoid doing zero-length writes. X-Git-Tag: go1.1rc2~890 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=722ee1f4797a81916b19e80df479058897c44923;p=gostls13.git os: Plan 9: avoid doing zero-length writes. Plan 9 I/O preserves message boundaries, while Go library code is written for UNIX-like operating systems which do not. Avoid doing zero-length writes in package os. R=rsc, rminnich, ality, rminnich, r CC=golang-dev https://golang.org/cl/7406046 --- diff --git a/src/pkg/os/file_plan9.go b/src/pkg/os/file_plan9.go index fabe5b979c..595275af20 100644 --- a/src/pkg/os/file_plan9.go +++ b/src/pkg/os/file_plan9.go @@ -244,13 +244,23 @@ func (f *File) pread(b []byte, off int64) (n int, err error) { // write writes len(b) bytes to the File. // It returns the number of bytes written and an error, if any. +// Since Plan 9 preserves message boundaries, never allow +// a zero-byte write. func (f *File) write(b []byte) (n int, err error) { + if len(b) == 0 { + return 0, nil + } return syscall.Write(f.fd, b) } // pwrite writes len(b) bytes to the File starting at byte offset off. // It returns the number of bytes written and an error, if any. +// Since Plan 9 preserves message boundaries, never allow +// a zero-byte write. func (f *File) pwrite(b []byte, off int64) (n int, err error) { + if len(b) == 0 { + return 0, nil + } return syscall.Pwrite(f.fd, b, off) }