Skip to content

Commit ba8ebc8

Browse files
committed
Kludge: work around lack of syscall.seek on 386 and arm, tinygo-org#1906
Revert this once syscall.seek is implemented cf. tinygo-org#1906
1 parent a3d60c4 commit ba8ebc8

File tree

5 files changed

+84
-27
lines changed

5 files changed

+84
-27
lines changed

src/os/file.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,19 +176,6 @@ func (f *File) Readdirnames(n int) (names []string, err error) {
176176
return nil, &PathError{"readdirnames", f.name, ErrNotImplemented}
177177
}
178178

179-
// Seek sets the offset for the next Read or Write on file to offset, interpreted
180-
// according to whence: 0 means relative to the origin of the file, 1 means
181-
// relative to the current offset, and 2 means relative to the end.
182-
// It returns the new offset and an error, if any.
183-
// The behavior of Seek on a file opened with O_APPEND is not specified.
184-
//
185-
// If f is a directory, the behavior of Seek varies by operating
186-
// system; you can seek to the beginning of the directory on Unix-like
187-
// operating systems, but not on Windows.
188-
func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
189-
return f.handle.Seek(offset, whence)
190-
}
191-
192179
func (f *File) SyscallConn() (syscall.RawConn, error) {
193180
return nil, ErrNotImplemented
194181
}

src/os/file_windows.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ func (f unixFileHandle) Seek(offset int64, whence int) (int64, error) {
7272
return newoffset, handleSyscallError(err)
7373
}
7474

75+
// Seek sets the offset for the next Read or Write on file to offset, interpreted
76+
// according to whence: 0 means relative to the origin of the file, 1 means
77+
// relative to the current offset, and 2 means relative to the end.
78+
// It returns the new offset and an error, if any.
79+
// The behavior of Seek on a file opened with O_APPEND is not specified.
80+
//
81+
// If f is a directory, the behavior of Seek varies by operating
82+
// system; you can seek to the beginning of the directory on Unix-like
83+
// operating systems, but not on Windows.
84+
// TODO: move this back to file.go once syscall.seek is implemented on 386 and arm.
85+
func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
86+
return f.handle.Seek(offset, whence)
87+
}
88+
7589
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
7690
// True is returned if name is 'NUL' whatever the case.
7791
func isWindowsNulName(name string) bool {

src/os/seek_unix_bad.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// +build linux,!baremetal,386 linux,!baremetal,arm
2+
3+
// Functions broken by lack of seek().
4+
// Stat is broken because it uses Time, which has a preadn function that uses seek :-(
5+
//
6+
// TODO: remove this file once tinygo gets syscall.Seek support on i386
7+
8+
// Copyright 2016 The Go Authors. All rights reserved.
9+
// Use of this source code is governed by a BSD-style
10+
// license that can be found in the LICENSE file.
11+
12+
package os
13+
14+
// Seek sets the offset for the next Read or Write on file to offset, interpreted
15+
// according to whence: 0 means relative to the origin of the file, 1 means
16+
// relative to the current offset, and 2 means relative to the end.
17+
// It returns the new offset and an error, if any.
18+
// The behavior of Seek on a file opened with O_APPEND is not specified.
19+
//
20+
// If f is a directory, the behavior of Seek varies by operating
21+
// system; you can seek to the beginning of the directory on Unix-like
22+
// operating systems, but not on Windows.
23+
func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
24+
return f.handle.Seek(offset, whence)
25+
}
26+
27+
// Stat returns the FileInfo structure describing file.
28+
// If there is an error, it will be of type *PathError.
29+
func (f *File) Stat() (FileInfo, error) {
30+
return nil, &PathError{Op: "fstat", Path: f.name, Err: ErrNotImplemented}
31+
}

src/os/seek_unix_good.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// +build darwin linux,!baremetal,!386,!arm
2+
3+
// Functions broken by lack of seek().
4+
// Stat is broken because it uses Time, which has a preadn function that uses seek :-(
5+
//
6+
// TODO: merge these functions back where they belong once tinygo gets syscall.Seek support on i386
7+
8+
package os
9+
10+
import (
11+
"syscall"
12+
)
13+
14+
// Seek sets the offset for the next Read or Write on file to offset, interpreted
15+
// according to whence: 0 means relative to the origin of the file, 1 means
16+
// relative to the current offset, and 2 means relative to the end.
17+
// It returns the new offset and an error, if any.
18+
// The behavior of Seek on a file opened with O_APPEND is not specified.
19+
//
20+
// If f is a directory, the behavior of Seek varies by operating
21+
// system; you can seek to the beginning of the directory on Unix-like
22+
// operating systems, but not on Windows.
23+
func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
24+
return f.handle.Seek(offset, whence)
25+
}
26+
27+
// Stat returns the FileInfo structure describing file.
28+
// If there is an error, it will be of type *PathError.
29+
func (f *File) Stat() (FileInfo, error) {
30+
var fs fileStat
31+
err := ignoringEINTR(func() error {
32+
return syscall.Fstat(int(f.handle.(unixFileHandle)), &fs.sys)
33+
})
34+
if err != nil {
35+
return nil, &PathError{Op: "fstat", Path: f.name, Err: err}
36+
}
37+
fillFileStatFromSys(&fs, f.name)
38+
return &fs, nil
39+
}

src/os/stat_unix.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,6 @@ func (f *File) Sync() error {
1515
return ErrNotImplemented
1616
}
1717

18-
// Stat returns the FileInfo structure describing file.
19-
// If there is an error, it will be of type *PathError.
20-
func (f *File) Stat() (FileInfo, error) {
21-
var fs fileStat
22-
err := ignoringEINTR(func() error {
23-
return syscall.Fstat(int(f.handle.(unixFileHandle)), &fs.sys)
24-
})
25-
if err != nil {
26-
return nil, &PathError{Op: "fstat", Path: f.name, Err: err}
27-
}
28-
fillFileStatFromSys(&fs, f.name)
29-
return &fs, nil
30-
}
31-
3218
// statNolog stats a file with no test logging.
3319
func statNolog(name string) (FileInfo, error) {
3420
var fs fileStat

0 commit comments

Comments
 (0)