mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-19 20:14:04 +00:00
os, syscall: implement ReadAt for unix
Windows will take more work, so test is skipped there.
This commit is contained in:
+17
-1
@@ -2,7 +2,10 @@
|
||||
|
||||
package os
|
||||
|
||||
import "syscall"
|
||||
import (
|
||||
"io"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
type syscallFd = int
|
||||
|
||||
@@ -22,3 +25,16 @@ func Pipe() (r *File, w *File, err error) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ReadAt reads up to len(b) bytes from the File starting at the given absolute offset.
|
||||
// It returns the number of bytes read and any error encountered, possibly io.EOF.
|
||||
// At end of file, Pread returns 0, io.EOF.
|
||||
// TODO: move to file_anyos once ReadAt is implemented for windows
|
||||
func (f unixFileHandle) ReadAt(b []byte, offset int64) (n int, err error) {
|
||||
n, err = syscall.Pread(syscallFd(f), b, offset)
|
||||
err = handleSyscallError(err)
|
||||
if n == 0 && err == nil {
|
||||
err = io.EOF
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user