1
0
mirror of https://github.com/golang/go synced 2024-11-25 02:07:58 -07:00

doc/progs: fix windows version to satisfy new error

R=rsc
CC=golang-dev
https://golang.org/cl/5376089
This commit is contained in:
Alex Brainman 2011-11-14 20:53:03 +11:00
parent 40afe58692
commit 36494b0acd

View File

@ -28,10 +28,7 @@ var (
) )
func OpenFile(name string, mode int, perm uint32) (file *File, err error) { func OpenFile(name string, mode int, perm uint32) (file *File, err error) {
r, e := syscall.Open(name, mode, perm) r, err := syscall.Open(name, mode, perm)
if e != 0 {
err = os.Errno(e)
}
return newFile(r, name), err return newFile(r, name), err
} }
@ -54,22 +51,16 @@ func (file *File) Close() error {
if file == nil { if file == nil {
return os.EINVAL return os.EINVAL
} }
e := syscall.Close(file.fd) err := syscall.Close(file.fd)
file.fd = syscall.InvalidHandle // so it can't be closed again file.fd = syscall.InvalidHandle // so it can't be closed again
if e != 0 { return err
return os.Errno(e)
}
return nil
} }
func (file *File) Read(b []byte) (ret int, err error) { func (file *File) Read(b []byte) (ret int, err error) {
if file == nil { if file == nil {
return -1, os.EINVAL return -1, os.EINVAL
} }
r, e := syscall.Read(file.fd, b) r, err := syscall.Read(file.fd, b)
if e != 0 {
err = os.Errno(e)
}
return int(r), err return int(r), err
} }
@ -77,10 +68,7 @@ func (file *File) Write(b []byte) (ret int, err error) {
if file == nil { if file == nil {
return -1, os.EINVAL return -1, os.EINVAL
} }
r, e := syscall.Write(file.fd, b) r, err := syscall.Write(file.fd, b)
if e != 0 {
err = os.Errno(e)
}
return int(r), err return int(r), err
} }