Skip to content

Commit

Permalink
syscall: libc_wasip2: fsync()
Browse files Browse the repository at this point in the history
  • Loading branch information
dgryski committed Feb 26, 2024
1 parent ca83500 commit 630f6e5
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion src/syscall/libc_wasip2.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,33 @@ func symlink(from, to *byte) int32 {
//
//go:export fsync
func fsync(fd int32) int32 {
return 0
if _, ok := wasiStreams[fd]; ok {
// can't sync a stream
libcErrno = EBADF
return -1
}

streams, ok := wasiFiles[fd]
if !ok {
libcErrno = EBADF
return -1
}
if streams.d == cm.ResourceNone {
libcErrno = EBADF
return -1
}
if streams.oflag&O_WRONLY == 0 {
libcErrno = EBADF
return -1
}

result := streams.d.SyncData()
if err := result.Err(); err != nil {
libcErrno = errorCodeToErrno(*err)
return -1
}

return 0
}

// ssize_t readlink(const char *path, void *buf, size_t count);
Expand Down

0 comments on commit 630f6e5

Please sign in to comment.