From 6193f7482633ef818604375d9755ded67946adfc Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Fri, 24 Nov 2023 06:13:18 +0000 Subject: [PATCH] fix: return ENOTSUP instead of -1 for unsupported syscalls Negative errno value is not expected at least by wasi-libc. --- src/fd.ts | 56 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/fd.ts b/src/fd.ts index 4a49b64..1cd0e18 100644 --- a/src/fd.ts +++ b/src/fd.ts @@ -3,85 +3,85 @@ import * as wasi from "./wasi_defs.js"; export class Fd { fd_advise(offset: bigint, len: bigint, advice: number): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_allocate(offset: bigint, len: bigint): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_close(): number { return 0; } fd_datasync(): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_fdstat_get(): { ret: number; fdstat: wasi.Fdstat | null } { - return { ret: -1, fdstat: null }; + return { ret: wasi.ERRNO_NOTSUP, fdstat: null }; } fd_fdstat_set_flags(flags: number): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_fdstat_set_rights( fs_rights_base: bigint, fs_rights_inheriting: bigint, ): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_filestat_get(): { ret: number; filestat: wasi.Filestat | null } { - return { ret: -1, filestat: null }; + return { ret: wasi.ERRNO_NOTSUP, filestat: null }; } fd_filestat_set_size(size: bigint): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_filestat_set_times(atim: bigint, mtim: bigint, fst_flags: number): number { - return -1; + return wasi.ERRNO_NOTSUP; } fd_pread(view8: Uint8Array, iovs: Array, offset: bigint) { - return { ret: -1, nread: 0 }; + return { ret: wasi.ERRNO_NOTSUP, nread: 0 }; } fd_prestat_get() { - return { ret: -1, prestat: null }; + return { ret: wasi.ERRNO_NOTSUP, prestat: null }; } fd_prestat_dir_name() { - return { ret: -1, prestat_dir_name: null }; + return { ret: wasi.ERRNO_NOTSUP, prestat_dir_name: null }; } fd_pwrite(view8: Uint8Array, iovs: Array, offset: bigint) { - return { ret: -1, nwritten: 0 }; + return { ret: wasi.ERRNO_NOTSUP, nwritten: 0 }; } fd_read( view8: Uint8Array, iovs: Array, ): { ret: number; nread: number } { - return { ret: -1, nread: 0 }; + return { ret: wasi.ERRNO_NOTSUP, nread: 0 }; } fd_readdir_single(cookie: bigint): { ret: number; dirent: wasi.Dirent | null; } { - return { ret: -1, dirent: null }; + return { ret: wasi.ERRNO_NOTSUP, dirent: null }; } fd_seek(offset: bigint, whence: number): { ret: number; offset: bigint } { - return { ret: -1, offset: 0n }; + return { ret: wasi.ERRNO_NOTSUP, offset: 0n }; } fd_sync(): number { return 0; } fd_tell(): { ret: number; offset: bigint } { - return { ret: -1, offset: 0n }; + return { ret: wasi.ERRNO_NOTSUP, offset: 0n }; } fd_write(view8: Uint8Array, iovs: Array) { - return { ret: -1, nwritten: 0 }; + return { ret: wasi.ERRNO_NOTSUP, nwritten: 0 }; } path_create_directory(path): number { - return -1; + return wasi.ERRNO_NOTSUP; } path_filestat_get(flags, path) { - return { ret: -1, filestat: null }; + return { ret: wasi.ERRNO_NOTSUP, filestat: null }; } path_filestat_set_times(flags, path, atim, mtim, fst_flags) { - return -1; + return wasi.ERRNO_NOTSUP; } path_link(old_fd, old_flags, old_path, new_path): number { - return -1; + return wasi.ERRNO_NOTSUP; } path_open( dirflags, @@ -91,21 +91,21 @@ export class Fd { fs_rights_inheriting, fdflags, ) { - return { ret: -1, fd_obj: null }; + return { ret: wasi.ERRNO_NOTSUP, fd_obj: null }; } path_readlink(path) { - return { ret: -1, data: null }; + return { ret: wasi.ERRNO_NOTSUP, data: null }; } path_remove_directory(path): number { - return -1; + return wasi.ERRNO_NOTSUP; } path_rename(old_path, new_fd, new_path): number { - return -1; + return wasi.ERRNO_NOTSUP; } path_symlink(old_path, new_path): number { - return -1; + return wasi.ERRNO_NOTSUP; } path_unlink_file(path): number { - return -1; + return wasi.ERRNO_NOTSUP; } }