]> Cypherpunks repositories - gostls13.git/commitdiff
read and write never return -1 now: error return is through the error variable only
authorRob Pike <r@golang.org>
Wed, 19 Nov 2008 06:32:01 +0000 (22:32 -0800)
committerRob Pike <r@golang.org>
Wed, 19 Nov 2008 06:32:01 +0000 (22:32 -0800)
R=rsc
DELTA=13  (9 added, 0 deleted, 4 changed)
OCL=19538
CL=19570

src/lib/os/os_file.go

index 2667a1e21296c7078c453ee4bd8029fcae72d1c8..0d2e7bd6a338d7d764a1b6ef3b68d3ee1c26f984 100644 (file)
@@ -55,35 +55,44 @@ func (fd *FD) Close() *Error {
 
 func (fd *FD) Read(b *[]byte) (ret int, err *Error) {
        if fd == nil {
-               return -1, EINVAL
+               return 0, EINVAL
        }
        var r, e int64;
        if len(b) > 0 {  // because we access b[0]
                r, e = syscall.read(fd.fd, &b[0], int64(len(b)));
+               if r < 0 {
+                       r = 0
+               }
        }
        return int(r), ErrnoToError(e)
 }
 
 func (fd *FD) Write(b *[]byte) (ret int, err *Error) {
        if fd == nil {
-               return -1, EINVAL
+               return 0, EINVAL
        }
        var r, e int64;
        if len(b) > 0 {  // because we access b[0]
                r, e = syscall.write(fd.fd, &b[0], int64(len(b)));
+               if r < 0 {
+                       r = 0
+               }
        }
        return int(r), ErrnoToError(e)
 }
 
 func (fd *FD) WriteString(s string) (ret int, err *Error) {
        if fd == nil {
-               return -1, EINVAL
+               return 0, EINVAL
        }
        b := new([]byte, len(s)+1);
        if !syscall.StringToBytes(b, s) {
-               return -1, EINVAL
+               return 0, EINVAL
        }
        r, e := syscall.write(fd.fd, &b[0], int64(len(s)));
+       if r < 0 {
+               r = 0
+       }
        return int(r), ErrnoToError(e)
 }