read and write never return -1 now: error return is through the error variable only

R=rsc
DELTA=13  (9 added, 0 deleted, 4 changed)
OCL=19538
CL=19570
This commit is contained in:
Rob Pike 2008-11-18 22:32:01 -08:00
parent 497e648e7e
commit addd6fa846
1 changed files with 13 additions and 4 deletions

View 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)
}