buf fix: make FD.Read, FD.Write work for empty buffers

R=r
DELTA=8  (6 added, 0 deleted, 2 changed)
OCL=19273
CL=19275
This commit is contained in:
Robert Griesemer 2008-11-14 15:13:29 -08:00
parent f3e354ec26
commit 23c8faaf85
1 changed files with 8 additions and 2 deletions

View File

@ -57,7 +57,10 @@ func (fd *FD) Read(b *[]byte) (ret int, err *Error) {
if fd == nil {
return -1, EINVAL
}
r, e := syscall.read(fd.fd, &b[0], int64(len(b)));
var r, e int64;
if len(b) > 0 { // because we access b[0]
r, e = syscall.read(fd.fd, &b[0], int64(len(b)));
}
return int(r), ErrnoToError(e)
}
@ -65,7 +68,10 @@ func (fd *FD) Write(b *[]byte) (ret int, err *Error) {
if fd == nil {
return -1, EINVAL
}
r, e := syscall.write(fd.fd, &b[0], int64(len(b)));
var r, e int64;
if len(b) > 0 { // because we access b[0]
r, e = syscall.write(fd.fd, &b[0], int64(len(b)));
}
return int(r), ErrnoToError(e)
}