Kludge: work around lack of syscall.seek on 386 and arm, #1906

Revert this once syscall.seek is implemented
cf. https://github.com/tinygo-org/tinygo/issues/1906
Этот коммит содержится в:
Dan Kegel 2022-01-18 01:03:34 +00:00 коммит произвёл Ron Evans
родитель 322abf6d22
коммит 60b483bd3b
5 изменённых файлов: 84 добавлений и 27 удалений

Просмотреть файл

@ -180,19 +180,6 @@ 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
}

Просмотреть файл

@ -82,6 +82,20 @@ 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 {

31
src/os/seek_unix_bad.go Обычный файл
Просмотреть файл

@ -0,0 +1,31 @@
// +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}
}

39
src/os/seek_unix_good.go Обычный файл
Просмотреть файл

@ -0,0 +1,39 @@
// +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
}

Просмотреть файл

@ -15,20 +15,6 @@ 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