os: do not assume syscall i/o funcs return n=0 on error
Fixes #9007.
LGTM=iant, r
R=r, iant
CC=golang-codereviews
https://golang.org/cl/160670043
diff --git a/src/os/file.go b/src/os/file.go
index b4a7458..e12428c 100644
--- a/src/os/file.go
+++ b/src/os/file.go
@@ -255,3 +255,12 @@
func Rename(oldpath, newpath string) error {
return rename(oldpath, newpath)
}
+
+// Many functions in package syscall return a count of -1 instead of 0.
+// Using fixCount(call()) instead of call() corrects the count.
+func fixCount(n int, err error) (int, error) {
+ if n < 0 {
+ n = 0
+ }
+ return n, err
+}