Commit addd6fa8 authored by Rob Pike's avatar Rob Pike

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
parent 497e648e
...@@ -55,35 +55,44 @@ func (fd *FD) Close() *Error { ...@@ -55,35 +55,44 @@ func (fd *FD) Close() *Error {
func (fd *FD) Read(b *[]byte) (ret int, err *Error) { func (fd *FD) Read(b *[]byte) (ret int, err *Error) {
if fd == nil { if fd == nil {
return -1, EINVAL return 0, EINVAL
} }
var r, e int64; var r, e int64;
if len(b) > 0 { // because we access b[0] if len(b) > 0 { // because we access b[0]
r, e = syscall.read(fd.fd, &b[0], int64(len(b))); r, e = syscall.read(fd.fd, &b[0], int64(len(b)));
if r < 0 {
r = 0
}
} }
return int(r), ErrnoToError(e) return int(r), ErrnoToError(e)
} }
func (fd *FD) Write(b *[]byte) (ret int, err *Error) { func (fd *FD) Write(b *[]byte) (ret int, err *Error) {
if fd == nil { if fd == nil {
return -1, EINVAL return 0, EINVAL
} }
var r, e int64; var r, e int64;
if len(b) > 0 { // because we access b[0] if len(b) > 0 { // because we access b[0]
r, e = syscall.write(fd.fd, &b[0], int64(len(b))); r, e = syscall.write(fd.fd, &b[0], int64(len(b)));
if r < 0 {
r = 0
}
} }
return int(r), ErrnoToError(e) return int(r), ErrnoToError(e)
} }
func (fd *FD) WriteString(s string) (ret int, err *Error) { func (fd *FD) WriteString(s string) (ret int, err *Error) {
if fd == nil { if fd == nil {
return -1, EINVAL return 0, EINVAL
} }
b := new([]byte, len(s)+1); b := new([]byte, len(s)+1);
if !syscall.StringToBytes(b, s) { if !syscall.StringToBytes(b, s) {
return -1, EINVAL return 0, EINVAL
} }
r, e := syscall.write(fd.fd, &b[0], int64(len(s))); r, e := syscall.write(fd.fd, &b[0], int64(len(s)));
if r < 0 {
r = 0
}
return int(r), ErrnoToError(e) return int(r), ErrnoToError(e)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment