Source file src/internal/syscall/unix/at_wasip1.go

     1  // Copyright 2020 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build wasip1
     6  
     7  package unix
     8  
     9  import (
    10  	"syscall"
    11  	"unsafe"
    12  )
    13  
    14  const (
    15  	// UTIME_OMIT is the sentinel value to indicate that a time value should not
    16  	// be changed. It is useful for example to indicate for example with UtimesNano
    17  	// to avoid changing AccessTime or ModifiedTime.
    18  	// Its value must match syscall/fs_wasip1.go
    19  	UTIME_OMIT = -0x2
    20  )
    21  
    22  func Openat(dirfd int, path string, flags int, perm uint32) (int, error) {
    23  	return syscall.Openat(dirfd, path, flags, perm)
    24  }
    25  
    26  func Readlinkat(dirfd int, path string, buf []byte) (int, error) {
    27  	var nwritten size
    28  	errno := path_readlink(
    29  		int32(dirfd),
    30  		unsafe.StringData(path),
    31  		size(len(path)),
    32  		&buf[0],
    33  		size(len(buf)),
    34  		&nwritten)
    35  	return int(nwritten), errnoErr(errno)
    36  
    37  }
    38  
    39  type (
    40  	size = uint32
    41  )
    42  
    43  //go:wasmimport wasi_snapshot_preview1 path_readlink
    44  //go:noescape
    45  func path_readlink(fd int32, path *byte, pathLen size, buf *byte, bufLen size, nwritten *size) syscall.Errno
    46  
    47  func Mkdirat(dirfd int, path string, mode uint32) error {
    48  	if path == "" {
    49  		return syscall.EINVAL
    50  	}
    51  	return errnoErr(path_create_directory(
    52  		int32(dirfd),
    53  		unsafe.StringData(path),
    54  		size(len(path)),
    55  	))
    56  }
    57  
    58  //go:wasmimport wasi_snapshot_preview1 path_create_directory
    59  //go:noescape
    60  func path_create_directory(fd int32, path *byte, pathLen size) syscall.Errno
    61  
    62  func errnoErr(errno syscall.Errno) error {
    63  	if errno == 0 {
    64  		return nil
    65  	}
    66  	return errno
    67  }
    68  

View as plain text