os: implement file.Seek, add smoke test

This commit is contained in:
Dan Kegel
2022-01-01 07:51:31 -08:00
committed by Ron Evans
parent 84279ab2ec
commit 998f01608c
7 changed files with 91 additions and 5 deletions
+10 -2
View File
@@ -46,8 +46,12 @@ func Pread(fd int, p []byte, offset int64) (n int, err error) {
return
}
func Seek(fd int, offset int64, whence int) (off int64, err error) {
return 0, ENOSYS // TODO
func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
newoffset = libc_lseek(int32(fd), offset, whence)
if newoffset < 0 {
err = getErrno()
}
return
}
func Open(path string, flag int, mode uint32) (fd int, err error) {
@@ -248,6 +252,10 @@ func libc_read(fd int32, buf *byte, count uint) int
//export pread
func libc_pread(fd int32, buf *byte, count uint, offset int64) int
// ssize_t lseek(int fd, off_t offset, int whence);
//export lseek
func libc_lseek(fd int32, offset int64, whence int) int64
// int open(const char *pathname, int flags, mode_t mode);
//export open
func libc_open(pathname *byte, flags int32, mode uint32) int32