os: add file.Truncate

This commit is contained in:
leongross
2024-08-02 08:22:46 -07:00
committed by GitHub
parent 417a26d20c
commit a8a532f9d6
6 changed files with 116 additions and 12 deletions
+8 -2
View File
@@ -432,7 +432,6 @@ func chmod(pathname *byte, mode uint32) int32 {
//
//export mkdir
func mkdir(pathname *byte, mode uint32) int32 {
path := goString(pathname)
dir, relPath := findPreopenForPath(path)
if dir.d == cm.ResourceNone {
@@ -773,7 +772,6 @@ var libcCWD wasiDir
var wasiPreopens map[string]types.Descriptor
func populatePreopens() {
var cwd string
// find CWD
@@ -1354,3 +1352,11 @@ func getcwd(buf *byte, size uint) *byte {
copy(s, cwd)
return buf
}
// int truncate(const char *path, off_t length);
//
//export truncate
func truncate(path *byte, length int64) int32 {
libcErrno = ENOSYS
return -1
}
+14
View File
@@ -203,6 +203,15 @@ func Execve(pathname string, argv []string, envv []string) (err error) {
return
}
func Truncate(path string, length int64) (err error) {
data := cstring(path)
fail := int(libc_truncate(&data[0], length))
if fail < 0 {
err = getErrno()
}
return
}
func Faccessat(dirfd int, path string, mode uint32, flags int) (err error)
func Kill(pid int, sig Signal) (err error) {
@@ -451,3 +460,8 @@ func libc_fork() int32
//
//export execve
func libc_execve(filename *byte, argv **byte, envp **byte) int
// int truncate(const char *path, off_t length);
//
//export truncate
func libc_truncate(path *byte, length int64) int32