From 722ee1f4797a81916b19e80df479058897c44923 Mon Sep 17 00:00:00 2001 From: Akshat Kumar Date: Fri, 22 Feb 2013 23:06:25 +0100 Subject: [PATCH] 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 --- src/pkg/os/file_plan9.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) } -- 2.48.1