01 | func (file *File) Close() os.Error { |
02 | if file == nil { |
03 | return os.EINVAL |
04 | } |
05 | e := syscall.Close(file.fd) |
06 | file.fd = -1 // so it can't be closed again |
07 | if e != 0 { |
08 | return os.Errno(e) |
09 | } |
10 | return nil |
11 | } |
01 | func (file *File) Read(b []byte) (ret int , err os.Error) { |
02 | if file == nil { |
03 | return -1, os.EINVAL |
04 | } |
05 | r, e := syscall.Read(file.fd, b) |
06 | if e != 0 { |
07 | err = os.Errno(e) |
08 | } |
09 | return int (r), err |
10 | } |
01 | func (file *File) Write(b []byte) (ret int , err os.Error) { |
02 | if file == nil { |
03 | return -1, os.EINVAL |
04 | } |
05 | r, e := syscall.Write(file.fd, b) |
06 | if e != 0 { |
07 | err = os.Errno(e) |
08 | } |
09 | return int (r), err |
10 | } |
1 | func (file *File) String() string { |
2 | return file.name |
3 | } |
联系客服