diff options
author | Russ Cox <rsc@golang.org> | 2014-10-28 15:00:13 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2014-10-28 15:00:13 -0400 |
commit | 45ce02fb3768d73154148259eac8c6dc787d56e7 (patch) | |
tree | 2819832837de89110ff6f09153bd3128a910035e /src/os/file_plan9.go | |
parent | e2c1e44befb3dc8e0f5c58843eaf0f0f787e029b (diff) | |
download | go-45ce02fb3768d73154148259eac8c6dc787d56e7.tar.gz |
os: do not assume syscall i/o funcs return n=0 on error
Fixes issue 9007.
LGTM=iant, r
R=r, iant
CC=golang-codereviews
https://codereview.appspot.com/160670043
Diffstat (limited to 'src/os/file_plan9.go')
-rw-r--r-- | src/os/file_plan9.go | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/src/os/file_plan9.go b/src/os/file_plan9.go index a804b8197..22860e20a 100644 --- a/src/os/file_plan9.go +++ b/src/os/file_plan9.go @@ -244,14 +244,14 @@ func (f *File) Sync() (err error) { // read reads up to len(b) bytes from the File. // It returns the number of bytes read and an error, if any. func (f *File) read(b []byte) (n int, err error) { - return syscall.Read(f.fd, b) + return fixCount(syscall.Read(f.fd, b)) } // pread reads len(b) bytes from the File starting at byte offset off. // It returns the number of bytes read and the error, if any. // EOF is signaled by a zero count with err set to nil. func (f *File) pread(b []byte, off int64) (n int, err error) { - return syscall.Pread(f.fd, b, off) + return fixCount(syscall.Pread(f.fd, b, off)) } // write writes len(b) bytes to the File. @@ -259,10 +259,7 @@ func (f *File) pread(b []byte, off int64) (n int, err error) { // 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) + return fixCount(syscall.Write(f.fd, b)) } // pwrite writes len(b) bytes to the File starting at byte offset off. @@ -273,7 +270,7 @@ 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) + return fixCount(syscall.Pwrite(f.fd, b, off)) } // seek sets the offset for the next Read or Write on file to offset, interpreted |