Skip to content

Commit c58d73a

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

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
@@ -180,19 +180,6 @@ func (f *File) Readdirnames(n int) (names []string, err error) {
180180
return nil, &PathError{"readdirnames", f.name, ErrNotImplemented}
181181
}
182182

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

src/os/file_windows.go

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

85+
// Seek sets the offset for the next Read or Write on file to offset, interpreted
86+
// according to whence: 0 means relative to the origin of the file, 1 means
87+
// relative to the current offset, and 2 means relative to the end.
88+
// It returns the new offset and an error, if any.
89+
// The behavior of Seek on a file opened with O_APPEND is not specified.
90+
//
91+
// If f is a directory, the behavior of Seek varies by operating
92+
// system; you can seek to the beginning of the directory on Unix-like
93+
// operating systems, but not on Windows.
94+
// TODO: move this back to file.go once syscall.seek is implemented on 386 and arm.
95+
func (f *File) Seek(offset int64, whence int) (ret int64, err error) {
96+
return f.handle.Seek(offset, whence)
97+
}
98+
8599
// isWindowsNulName reports whether name is os.DevNull ('NUL') on Windows.
86100
// True is returned if name is 'NUL' whatever the case.
87101
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,!wasi
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 wasi
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)