From 4d739ba5924c70ed8091934fc1deaafb7db93ee0 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 21 May 2022 17:06:43 -0500 Subject: [PATCH] added missing fs procedures to wasi runtime --- core/wasi/wasi_fs.onyx | 30 ++++++++++++++++++++++++++++++ scripts/onyx-pkg.onyx | 1 - 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/core/wasi/wasi_fs.onyx b/core/wasi/wasi_fs.onyx index b4b89709..6422ef46 100644 --- a/core/wasi/wasi_fs.onyx +++ b/core/wasi/wasi_fs.onyx @@ -132,6 +132,16 @@ __file_remove :: (path: str) -> bool { return removed; } +__file_rename :: (old_path: str, new_path: str) -> bool { + renamed := false; + for .[3, 4] { // Trying both preopened directories + err := wasi.path_rename(it, old_path, it, new_path); + if err == .Success do renamed = true; + } + + return renamed; +} + __file_stream_vtable := io.Stream_Vtable.{ seek = (use fs: ^os.File, to: i32, whence: io.SeekFrom) -> io.Error { // Currently, the new offset is just ignored. @@ -282,3 +292,23 @@ __dir_read :: (dir: DirectoryData, out_entry: ^os.DirectoryEntry) -> bool { dir.last_cookie = dirent.d_next; return true; } + +__dir_create :: (path: str) -> bool { + created := false; + for .[3, 4] { // Trying both preopened directories + err := wasi.path_create_directory(it, path); + if err == .Success do created = true; + } + + return created; +} + +__dir_remove :: (path: str) -> bool { + removed := false; + for .[3, 4] { // Trying both preopened directories + err := wasi.path_remove_directory(it, path); + if err == .Success do removed = true; + } + + return removed; +} diff --git a/scripts/onyx-pkg.onyx b/scripts/onyx-pkg.onyx index e66640cb..4ef06eb8 100644 --- a/scripts/onyx-pkg.onyx +++ b/scripts/onyx-pkg.onyx @@ -97,7 +97,6 @@ run_init_command :: (args: [] cstr) { read_field :: macro (f: str, dest: ^$T) { while true { print(f); - r->skip_whitespace(); line := r->read_line(consume_newline=true, allocator=context.temp_allocator) |> string.strip_whitespace(); -- 2.25.1