diff --git a/examples/benchmarks/input_output/interleave_promises.effekt b/examples/benchmarks/input_output/interleave_promises.effekt index 1363530ff..ffc10fc56 100644 --- a/examples/benchmarks/input_output/interleave_promises.effekt +++ b/examples/benchmarks/input_output/interleave_promises.effekt @@ -23,11 +23,11 @@ def run(n: Int) = { promise(box { with on[IOError].result val filename = foldername ++ i.show ++ ".txt" - val file = open(filename, WriteOnly()) + val file = openForWriting(filename) val buffer = bytearray(size, 35.toByte) repeat(8) { - val i = write(file, buffer, 0, size, -1) - if (i < size) { + val m = write(file, buffer, 0, size, -1) + if (m < buffer.size) { panic("failed write") } } @@ -38,11 +38,11 @@ def run(n: Int) = { promises.foreachIndex { (i, p) => p.await().value() val filename = foldername ++ i.show ++ ".txt" - val file = open(filename, ReadOnly()) + val file = openForReading(filename) val buffer = bytearray::allocate(size) repeat(8) { - val i = read(file, buffer, 0, size, -1) - if (i < size) { + val m = read(file, buffer, 0, size, -1) + if (m < buffer.size) { panic("failed read") } } diff --git a/examples/benchmarks/input_output/large_file.effekt b/examples/benchmarks/input_output/large_file.effekt index 278b8c2e2..ec450d3a6 100644 --- a/examples/benchmarks/input_output/large_file.effekt +++ b/examples/benchmarks/input_output/large_file.effekt @@ -6,33 +6,38 @@ import io/filesystem def run(n: Int) = { - with on[IOError].panic; val filename = "/tmp/large_file.txt" val size = 4096 val _ = { - val file = open(filename, WriteOnly()) + val file = internal::openForWriting(filename) + if (file < 0) { + panic("failed open for writing") + } val outputBuffer = bytearray(size, 33.toByte) outputBuffer.unsafeSet(999, 10.toByte) repeat(n) { - val i = write(file, outputBuffer, 0, size, -1) - if (i < size) { + val m = internal::write(file, outputBuffer, 0, size, -1) + if (m < outputBuffer.size) { panic("failed write") } } - close(file) + internal::close(file) } - val file = open(filename, ReadOnly()) + val file = internal::openForReading(filename) + if (file < 0) { + panic("failed open for reading") + } val inputBuffer = bytearray::allocate(size) repeat(n) { - val i = read(file, inputBuffer, 0, size, -1) - if (i < size) { + val m = internal::read(file, inputBuffer, 0, size, -1) + if (m < inputBuffer.size) { panic("failed read") } } - close(file) + internal::close(file) return 0 } diff --git a/examples/benchmarks/input_output/small_files.effekt b/examples/benchmarks/input_output/small_files.effekt index 1638b8608..32e2acf86 100644 --- a/examples/benchmarks/input_output/small_files.effekt +++ b/examples/benchmarks/input_output/small_files.effekt @@ -6,34 +6,42 @@ import io/filesystem def run(n: Int) = { - with on[IOError].panic; val foldername = "/tmp/small_files/" val size = 4096 - on[IOError].result { mkdir(foldername) } match { - case Error(EEXIST(), msg) => () - case Error(e, m) => do raise(e, m) - case Success(()) => () + val code = internal::mkdir(foldername) + if (code < 0 && code != -17) { + panic("failed to make directory") } val buffer = bytearray(size, 33.toByte) each(0, n) { i => val filename = foldername ++ i.show ++ ".txt" - val file = open(filename, WriteOnly()) - if (write(file, buffer, 0, size, -1) < size) { + val file = internal::openForWriting(filename) + if (file < 0) { + panic("failed open for writing") + } + val m = internal::write(file, buffer, 0, size, -1) + if (m < buffer.size) { panic("failed write") } - close(file) + val _ = internal::close(file) + () } each(0, n) { i => val filename = foldername ++ i.show ++ ".txt" - val file = open(filename, ReadOnly()) - if (read(file, buffer, 0, size, -1) < size) { + val file = internal::openForReading(filename) + if (file < 0) { + panic("failed open for reading") + } + val m = internal::read(file, buffer, 0, size, -1) + if (m < buffer.size) { panic("failed read") } - close(file) + val _ = internal::close(file) + () } return 0 diff --git a/libraries/llvm/io.c b/libraries/llvm/io.c index 3383ecd5c..1d17b38f5 100644 --- a/libraries/llvm/io.c +++ b/libraries/llvm/io.c @@ -71,7 +71,7 @@ void c_fs_open(String path, int flags, Stack stack) { uv_fs_t* request = malloc(sizeof(uv_fs_t)); request->data = stack; - int result = uv_fs_open(uv_default_loop(), request, path_str, flags, 0666, c_resume_int_fs); + int result = uv_fs_open(uv_default_loop(), request, path_str, flags, 0777, c_resume_int_fs); if (result < 0) { uv_fs_req_cleanup(request); @@ -157,7 +157,7 @@ void c_fs_mkdir(String path, Stack stack) { request->data = stack; // Perform the mkdir operation - int result = uv_fs_mkdir(uv_default_loop(), request, path_str, 0666, c_resume_int_fs); + int result = uv_fs_mkdir(uv_default_loop(), request, path_str, 0777, c_resume_int_fs); if (result < 0) { uv_fs_req_cleanup(request);