]> Cypherpunks repositories - gostls13.git/commitdiff
syscalls can return negative i/o counts. fix bugs in ReadAt and WriteAt not to include
authorRob Pike <r@golang.org>
Wed, 9 Dec 2009 22:18:32 +0000 (14:18 -0800)
committerRob Pike <r@golang.org>
Wed, 9 Dec 2009 22:18:32 +0000 (14:18 -0800)
negative counts in return values.

R=rsc
CC=golang-dev
https://golang.org/cl/170044

src/pkg/os/file.go

index 03c6d57018cecc092892d4a7e91c6c7aac9bd8c3..459b78cc22530bd852f34accc22ae4e1c969b701 100644 (file)
@@ -141,11 +141,11 @@ func (file *File) ReadAt(b []byte, off int64) (n int, err Error) {
                if m == 0 && e == 0 {
                        return n, EOF
                }
-               n += m;
                if e != 0 {
                        err = &PathError{"read", file.name, Errno(e)};
                        break;
                }
+               n += m;
                b = b[m:];
                off += int64(m);
        }
@@ -186,11 +186,11 @@ func (file *File) WriteAt(b []byte, off int64) (n int, err Error) {
        }
        for len(b) > 0 {
                m, e := syscall.Pwrite(file.fd, b, off);
-               n += m;
                if e != 0 {
                        err = &PathError{"write", file.name, Errno(e)};
                        break;
                }
+               n += m;
                b = b[m:];
                off += int64(m);
        }