diff options
author | Michael Stapelberg <stapelberg@debian.org> | 2013-12-03 09:43:15 +0100 |
---|---|---|
committer | Michael Stapelberg <stapelberg@debian.org> | 2013-12-03 09:43:15 +0100 |
commit | 64d2a7c8945ba05af859901f5e248f1befdd8621 (patch) | |
tree | 013fcb7e9e3296ecdda876012252c36bd6bcb063 /src/pkg/os/file_windows.go | |
parent | b901efe83e212f0c34c769c079e41373da12d723 (diff) | |
download | golang-64d2a7c8945ba05af859901f5e248f1befdd8621.tar.gz |
Imported Upstream version 1.2upstream/1.2
Diffstat (limited to 'src/pkg/os/file_windows.go')
-rw-r--r-- | src/pkg/os/file_windows.go | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/pkg/os/file_windows.go b/src/pkg/os/file_windows.go index 82af756d8..fab7de342 100644 --- a/src/pkg/os/file_windows.go +++ b/src/pkg/os/file_windows.go @@ -153,6 +153,9 @@ func OpenFile(name string, flag int, perm FileMode) (file *File, err error) { // Close closes the File, rendering it unusable for I/O. // It returns an error, if any. func (file *File) Close() error { + if file == nil { + return ErrInvalid + } return file.file.close() } @@ -251,8 +254,14 @@ func (f *File) readConsole(b []byte) (n int, err error) { return 0, nil } if len(f.readbuf) == 0 { + // syscall.ReadConsole seems to fail, if given large buffer. + // So limit the buffer to 16000 characters. + numBytes := len(b) + if numBytes > 16000 { + numBytes = 16000 + } // get more input data from os - wchars := make([]uint16, len(b)) + wchars := make([]uint16, numBytes) var p *uint16 if len(b) > 0 { p = &wchars[0] @@ -306,6 +315,10 @@ func (f *File) pread(b []byte, off int64) (n int, err error) { var done uint32 e = syscall.ReadFile(syscall.Handle(f.fd), b, &done, &o) if e != nil { + if e == syscall.ERROR_HANDLE_EOF { + // end of file + return 0, nil + } return 0, e } return int(done), nil |