diff --git a/src/os/file.go b/src/os/file.go index 6735aae2..3589c377 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -180,6 +180,19 @@ func (f *File) Readdirnames(n int) (names []string, err error) { return nil, &PathError{"readdirnames", f.name, ErrNotImplemented} } +// Seek sets the offset for the next Read or Write on file to offset, interpreted +// according to whence: 0 means relative to the origin of the file, 1 means +// relative to the current offset, and 2 means relative to the end. +// It returns the new offset and an error, if any. +// The behavior of Seek on a file opened with O_APPEND is not specified. +// +// If f is a directory, the behavior of Seek varies by operating +// system; you can seek to the beginning of the directory on Unix-like +// operating systems, but not on Windows. +func (f *File) Seek(offset int64, whence int) (ret int64, err error) { + return f.handle.Seek(offset, whence) +} + func (f *File) SyscallConn() (syscall.RawConn, error) { return nil, ErrNotImplemented } diff --git a/src/os/file_windows.go b/src/os/file_windows.go index be0c3ece..3e1c63b9 100644 --- a/src/os/file_windows.go +++ b/src/os/file_windows.go @@ -82,20 +82,6 @@ func (f unixFileHandle) Seek(offset int64, whence int) (int64, error) { return newoffset, handleSyscallError(err) } -// Seek sets the offset for the next Read or Write on file to offset, interpreted -// according to whence: 0 means relative to the origin of the file, 1 means -// relative to the current offset, and 2 means relative to the end. -// It returns the new offset and an error, if any. -// The behavior of Seek on a file opened with O_APPEND is not specified. -// -// If f is a directory, the behavior of Seek varies by operating -// system; you can seek to the beginning of the directory on Unix-like -// operating systems, but not on Windows. -// TODO: move this back to file.go once syscall.seek is implemented on 386 and arm. -func (f *File) Seek(offset int64, whence int) (ret int64, err error) { - return f.handle.Seek(offset, whence) -} - // isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows. // True is returned if name is 'NUL' whatever the case. func isWindowsNulName(name string) bool { diff --git a/src/os/seek_unix_bad.go b/src/os/seek_unix_bad.go deleted file mode 100644 index e143ac9c..00000000 --- a/src/os/seek_unix_bad.go +++ /dev/null @@ -1,31 +0,0 @@ -// +build linux,!baremetal,386 linux,!baremetal,arm,!wasi - -// Functions broken by lack of seek(). -// Stat is broken because it uses Time, which has a preadn function that uses seek :-( -// -// TODO: remove this file once tinygo gets syscall.Seek support on i386 - -// Copyright 2016 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. - -package os - -// Seek sets the offset for the next Read or Write on file to offset, interpreted -// according to whence: 0 means relative to the origin of the file, 1 means -// relative to the current offset, and 2 means relative to the end. -// It returns the new offset and an error, if any. -// The behavior of Seek on a file opened with O_APPEND is not specified. -// -// If f is a directory, the behavior of Seek varies by operating -// system; you can seek to the beginning of the directory on Unix-like -// operating systems, but not on Windows. -func (f *File) Seek(offset int64, whence int) (ret int64, err error) { - return f.handle.Seek(offset, whence) -} - -// Stat returns the FileInfo structure describing file. -// If there is an error, it will be of type *PathError. -func (f *File) Stat() (FileInfo, error) { - return nil, &PathError{Op: "fstat", Path: f.name, Err: ErrNotImplemented} -} diff --git a/src/os/seek_unix_good.go b/src/os/seek_unix_good.go deleted file mode 100644 index 3a037402..00000000 --- a/src/os/seek_unix_good.go +++ /dev/null @@ -1,39 +0,0 @@ -// +build darwin linux,!baremetal,!386,!arm wasi - -// Functions broken by lack of seek(). -// Stat is broken because it uses Time, which has a preadn function that uses seek :-( -// -// TODO: merge these functions back where they belong once tinygo gets syscall.Seek support on i386 - -package os - -import ( - "syscall" -) - -// Seek sets the offset for the next Read or Write on file to offset, interpreted -// according to whence: 0 means relative to the origin of the file, 1 means -// relative to the current offset, and 2 means relative to the end. -// It returns the new offset and an error, if any. -// The behavior of Seek on a file opened with O_APPEND is not specified. -// -// If f is a directory, the behavior of Seek varies by operating -// system; you can seek to the beginning of the directory on Unix-like -// operating systems, but not on Windows. -func (f *File) Seek(offset int64, whence int) (ret int64, err error) { - return f.handle.Seek(offset, whence) -} - -// Stat returns the FileInfo structure describing file. -// If there is an error, it will be of type *PathError. -func (f *File) Stat() (FileInfo, error) { - var fs fileStat - err := ignoringEINTR(func() error { - return syscall.Fstat(int(f.handle.(unixFileHandle)), &fs.sys) - }) - if err != nil { - return nil, &PathError{Op: "fstat", Path: f.name, Err: err} - } - fillFileStatFromSys(&fs, f.name) - return &fs, nil -} diff --git a/src/os/stat_unix.go b/src/os/stat_unix.go index 9187b54e..02e3e1aa 100644 --- a/src/os/stat_unix.go +++ b/src/os/stat_unix.go @@ -15,6 +15,20 @@ func (f *File) Sync() error { return ErrNotImplemented } +// Stat returns the FileInfo structure describing file. +// If there is an error, it will be of type *PathError. +func (f *File) Stat() (FileInfo, error) { + var fs fileStat + err := ignoringEINTR(func() error { + return syscall.Fstat(int(f.handle.(unixFileHandle)), &fs.sys) + }) + if err != nil { + return nil, &PathError{Op: "fstat", Path: f.name, Err: err} + } + fillFileStatFromSys(&fs, f.name) + return &fs, nil +} + // statNolog stats a file with no test logging. func statNolog(name string) (FileInfo, error) { var fs fileStat