aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-08-09 12:33:21 +0100
committergingerBill <bill@gingerbill.org>2021-08-09 12:33:21 +0100
commitd99ed692baf8c2d6a89b907bf48c2d2fb175a6c8 (patch)
treebb1221396212a17d192194767c751c838467693a
parent4d00c2b800266346bda25e32797f6a4319c2ef51 (diff)
Add utility procedures: `io.read_ptr`; `io.write_ptr`; `io.read_ptr_at`; `io.write_ptr_at`
-rw-r--r--core/io/util.odin18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/io/util.odin b/core/io/util.odin
index 193c6153e..38243e953 100644
--- a/core/io/util.odin
+++ b/core/io/util.odin
@@ -1,7 +1,25 @@
package io
+import "core:mem"
import "core:strconv"
+
+read_ptr :: proc(r: Reader, p: rawptr, byte_size: int) -> (n: int, err: Error) {
+ return read(r, mem.byte_slice(p, byte_size));
+}
+
+write_ptr :: proc(w: Writer, p: rawptr, byte_size: int) -> (n: int, err: Error) {
+ return write(w, mem.byte_slice(p, byte_size));
+}
+
+read_ptr_at :: proc(r: Reader_At, p: rawptr, byte_size: int, offset: i64) -> (n: int, err: Error) {
+ return read_at(r, mem.byte_slice(p, byte_size), offset);
+}
+
+write_ptr_at :: proc(w: Writer_At, p: rawptr, byte_size: int, offset: i64) -> (n: int, err: Error) {
+ return write_at(w, mem.byte_slice(p, byte_size), offset);
+}
+
write_u64 :: proc(w: Writer, i: u64, base: int = 10) -> (n: int, err: Error) {
buf: [32]byte;
s := strconv.append_bits(buf[:], i, base, false, 64, strconv.digits, nil);