Skip to content

Commit 630f6e5

Browse files
committed
syscall: libc_wasip2: fsync()
1 parent ca83500 commit 630f6e5

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

src/syscall/libc_wasip2.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,33 @@ func symlink(from, to *byte) int32 {
497497
//
498498
//go:export fsync
499499
func fsync(fd int32) int32 {
500-
return 0
500+
if _, ok := wasiStreams[fd]; ok {
501+
// can't sync a stream
502+
libcErrno = EBADF
503+
return -1
504+
}
501505

506+
streams, ok := wasiFiles[fd]
507+
if !ok {
508+
libcErrno = EBADF
509+
return -1
510+
}
511+
if streams.d == cm.ResourceNone {
512+
libcErrno = EBADF
513+
return -1
514+
}
515+
if streams.oflag&O_WRONLY == 0 {
516+
libcErrno = EBADF
517+
return -1
518+
}
519+
520+
result := streams.d.SyncData()
521+
if err := result.Err(); err != nil {
522+
libcErrno = errorCodeToErrno(*err)
523+
return -1
524+
}
525+
526+
return 0
502527
}
503528

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

0 commit comments

Comments
 (0)