added missing fs procedures to wasi runtime
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 21 May 2022 22:06:43 +0000 (17:06 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Sat, 21 May 2022 22:06:43 +0000 (17:06 -0500)
core/wasi/wasi_fs.onyx
scripts/onyx-pkg.onyx

index b4b89709414e17eeb9da0f2ceda7a607ad078e20..6422ef4636ebbe8c63922f518356075d1d28c07f 100644 (file)
@@ -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;
+}
index e66640cb72355c4caaf2cd4303e1f52af49d86b1..4ef06eb8d76465234d4db6cd2a7be3c268c9dd04 100644 (file)
@@ -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();