forgot to add file_size
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 12 Dec 2021 04:18:28 +0000 (22:18 -0600)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sun, 12 Dec 2021 04:18:28 +0000 (22:18 -0600)
core/os/onyx_fs.onyx
modules/onyx_runtime/onyx_runtime.c

index c177e761e0cdff4df9094518850761996eccda3a..48f31833ec9337ebc68bd3657262ad5d21e5f63c 100644 (file)
@@ -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);
     },
 };
 
index f2ce9e61a24bfc5c4afebe0db1c46c2c48debfe3..906c4c754835852e5f74d27712d73e7fb04e3fff 100644 (file)
@@ -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)