]> Cypherpunks repositories - gostls13.git/commitdiff
os: Plan 9: avoid doing zero-length writes.
authorAkshat Kumar <seed@mail.nanosouffle.net>
Fri, 22 Feb 2013 22:06:25 +0000 (23:06 +0100)
committerRon Minnich <rminnich@gmail.com>
Fri, 22 Feb 2013 22:06:25 +0000 (23:06 +0100)
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

src/pkg/os/file_plan9.go

index fabe5b979ca30ef1c1f8a1f6b72dd1c996210812..595275af2022589cb9f3c35832cfc4b8505ad550 100644 (file)
@@ -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)
 }