mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-20 12:29:03 +00:00
properly handle unix read on directory
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//go:build !baremetal && !js && !wasm_unknown && !nintendoswitch
|
||||
|
||||
// Portions copyright 2009 The Go Authors. All rights reserved.
|
||||
// Portions copyright 2009-2024 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
@@ -97,6 +97,11 @@ type unixFileHandle uintptr
|
||||
// read and any error encountered. At end of file, Read returns 0, io.EOF.
|
||||
func (f unixFileHandle) Read(b []byte) (n int, err error) {
|
||||
n, err = syscall.Read(syscallFd(f), b)
|
||||
// In case of EISDIR, n == -1.
|
||||
// This breaks the assumption that n always represent the number of read bytes.
|
||||
if err == syscall.EISDIR {
|
||||
n = 0
|
||||
}
|
||||
err = handleSyscallError(err)
|
||||
if n == 0 && len(b) > 0 && err == nil {
|
||||
err = io.EOF
|
||||
|
||||
Reference in New Issue
Block a user