Skip to content

Commit 48d9ab9

Browse files
committed
stub truncate for wasip2
Signed-off-by: leongross <[email protected]>
1 parent 3a412b2 commit 48d9ab9

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/os/file_unix.go

-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,6 @@ func Readlink(name string) (string, error) {
128128
// Truncate changes the size of the file.
129129
// It does not change the I/O offset.
130130
// If there is an error, it will be of type *PathError.
131-
132131
// Alternatively just use 'raw' syscall by file name
133132
func (f *File) Truncate(size int64) (err error) {
134133
if f.handle == nil {

src/os/truncate_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ import (
1414
)
1515

1616
func TestTruncate(t *testing.T) {
17-
if runtime.GOOS == "windows" {
18-
t.Skip()
17+
// Truncate is not supported on Windows or wasi at the moment
18+
if runtime.GOOS == "windows" || runtime.GOOS == "wasip1" || runtime.GOOS == "wasip2" {
19+
t.Logf("skipping test on %s", runtime.GOOS)
20+
return
1921
}
2022

2123
tmpDir := t.TempDir()
@@ -25,6 +27,7 @@ func TestTruncate(t *testing.T) {
2527
if err != nil {
2628
t.Fatalf("create %q: got %v, want nil", file, err)
2729
}
30+
defer fd.Close()
2831

2932
// truncate up to 0x100
3033
if err := fd.Truncate(0x100); err != nil {

src/syscall/libc_wasip2.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,6 @@ func chmod(pathname *byte, mode uint32) int32 {
432432
//
433433
//export mkdir
434434
func mkdir(pathname *byte, mode uint32) int32 {
435-
436435
path := goString(pathname)
437436
dir, relPath := findPreopenForPath(path)
438437
if dir.d == cm.ResourceNone {
@@ -773,7 +772,6 @@ var libcCWD wasiDir
773772
var wasiPreopens map[string]types.Descriptor
774773

775774
func populatePreopens() {
776-
777775
var cwd string
778776

779777
// find CWD
@@ -1354,3 +1352,11 @@ func getcwd(buf *byte, size uint) *byte {
13541352
copy(s, cwd)
13551353
return buf
13561354
}
1355+
1356+
// int truncate(const char *path, off_t length);
1357+
//
1358+
//export truncate
1359+
func truncate(path *byte, length int64) int32 {
1360+
libcErrno = ENOSYS
1361+
return -1
1362+
}

src/syscall/syscall_libc.go

-3
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,3 @@ func libc_execve(filename *byte, argv **byte, envp **byte) int
465465
//
466466
//export truncate
467467
func libc_truncate(path *byte, length int64) int32
468-
469-
//go:extern environ
470-
var libc_environ *unsafe.Pointer

0 commit comments

Comments
 (0)