From 8bda84a95cc1e2de6180b028f9e3738f4f10cb15 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 11 Dec 2021 22:18:28 -0600 Subject: [PATCH] forgot to add file_size --- core/os/onyx_fs.onyx | 2 ++ modules/onyx_runtime/onyx_runtime.c | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/core/os/onyx_fs.onyx b/core/os/onyx_fs.onyx index c177e761..48f31833 100644 --- a/core/os/onyx_fs.onyx +++ b/core/os/onyx_fs.onyx @@ -29,6 +29,7 @@ __file_open :: (path: str, mode := os.OpenMode.Read) -> (FileData, os.FileError) __file_read :: (handle: FileData.Handle, output_buffer: [] u8, bytes_read: ^u64) -> io.Error --- __file_write :: (handle: FileData.Handle, input_buffer: [] u8, bytes_wrote: ^u64) -> io.Error --- __file_flush :: (handle: FileData.Handle) -> io.Error --- + __file_size :: (handle: FileData.Handle) -> u32 --- __dir_open :: (path: str, dir: ^DirectoryData) -> bool --- __dir_close :: (dir: DirectoryData) -> void --- @@ -93,6 +94,7 @@ __file_stream_vtable := io.Stream_Vtable.{ }, size = (use fs: ^os.File) -> i32 { + return __file_size(data.handle); }, }; diff --git a/modules/onyx_runtime/onyx_runtime.c b/modules/onyx_runtime/onyx_runtime.c index f2ce9e61..906c4c75 100644 --- a/modules/onyx_runtime/onyx_runtime.c +++ b/modules/onyx_runtime/onyx_runtime.c @@ -148,6 +148,13 @@ ONYX_DEF(__file_flush, (WASM_I64), (WASM_I32)) { return NULL; } +ONYX_DEF(__file_size, (WASM_I64), (WASM_I32)) { + i64 fd = params->data[0].of.i64; + bh_file file = { (bh_file_descriptor) fd }; + results->data[0] = WASM_I32_VAL(bh_file_size(&file)); + return NULL; +} + ONYX_DEF(__file_get_standard, (WASM_I32, WASM_I32), (WASM_I32)) { bh_file_standard standard = (bh_file_standard) params->data[0].of.i32; @@ -756,6 +763,7 @@ ONYX_LIBRARY { ONYX_FUNC(__file_read) ONYX_FUNC(__file_write) ONYX_FUNC(__file_flush) + ONYX_FUNC(__file_size) ONYX_FUNC(__file_get_standard) ONYX_FUNC(__dir_open) -- 2.25.1