From 5d190b15d7a665ada76ad752e2b41b4e6456c075 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 5 May 2022 15:30:07 +0100 Subject: [PATCH] Minor improvements to io and os --- core/io/io.odin | 9 ++------- core/os/os.odin | 4 ++++ core/os/os_darwin.odin | 3 --- core/os/os_freebsd.odin | 3 --- core/os/os_linux.odin | 3 --- core/os/os_openbsd.odin | 4 ---- 6 files changed, 6 insertions(+), 20 deletions(-) diff --git a/core/io/io.odin b/core/io/io.odin index e9d839efb..3ad34d607 100644 --- a/core/io/io.odin +++ b/core/io/io.odin @@ -4,7 +4,6 @@ package io import "core:intrinsics" -import "core:runtime" import "core:unicode/utf8" // Seek whence values @@ -254,11 +253,7 @@ read_at :: proc(r: Reader_At, p: []byte, offset: i64, n_read: ^int = nil) -> (n: return 0, .Empty } - curr_offset: i64 - curr_offset, err = r->impl_seek(offset, .Current) - if err != nil { - return 0, err - } + curr_offset := r->impl_seek(offset, .Current) or_return n, err = r->impl_read(p) _, err1 := r->impl_seek(curr_offset, .Start) @@ -552,7 +547,7 @@ _copy_buffer :: proc(dst: Writer, src: Reader, buf: []byte) -> (written: i64, er } } // NOTE(bill): alloca is fine here - buf = transmute([]byte)runtime.Raw_Slice{intrinsics.alloca(size, 2*align_of(rawptr)), size} + buf = intrinsics.alloca(size, 2*align_of(rawptr))[:size] } for { nr, er := read(src, buf) diff --git a/core/os/os.odin b/core/os/os.odin index e880ec21e..5e71e720e 100644 --- a/core/os/os.odin +++ b/core/os/os.odin @@ -9,6 +9,10 @@ OS :: ODIN_OS ARCH :: ODIN_ARCH ENDIAN :: ODIN_ENDIAN +SEEK_SET :: 0 +SEEK_CUR :: 1 +SEEK_END :: 2 + write_string :: proc(fd: Handle, str: string) -> (int, Errno) { return write(fd, transmute([]byte)str) } diff --git a/core/os/os_darwin.odin b/core/os/os_darwin.odin index ae5336849..21e9e54f4 100644 --- a/core/os/os_darwin.odin +++ b/core/os/os_darwin.odin @@ -163,9 +163,6 @@ O_SYNC :: 0x0080 O_ASYNC :: 0x0040 O_CLOEXEC :: 0x1000000 -SEEK_SET :: 0 -SEEK_CUR :: 1 -SEEK_END :: 2 SEEK_DATA :: 3 SEEK_HOLE :: 4 SEEK_MAX :: SEEK_HOLE diff --git a/core/os/os_freebsd.odin b/core/os/os_freebsd.odin index 4a95028c1..6545423d4 100644 --- a/core/os/os_freebsd.odin +++ b/core/os/os_freebsd.odin @@ -123,9 +123,6 @@ O_ASYNC :: 0x02000 O_CLOEXEC :: 0x80000 -SEEK_SET :: 0 -SEEK_CUR :: 1 -SEEK_END :: 2 SEEK_DATA :: 3 SEEK_HOLE :: 4 SEEK_MAX :: SEEK_HOLE diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin index ed73341c0..9b712cecc 100644 --- a/core/os/os_linux.odin +++ b/core/os/os_linux.odin @@ -167,9 +167,6 @@ O_ASYNC :: 0x02000 O_CLOEXEC :: 0x80000 -SEEK_SET :: 0 -SEEK_CUR :: 1 -SEEK_END :: 2 SEEK_DATA :: 3 SEEK_HOLE :: 4 SEEK_MAX :: SEEK_HOLE diff --git a/core/os/os_openbsd.odin b/core/os/os_openbsd.odin index a99c8fef0..dd230f9b5 100644 --- a/core/os/os_openbsd.odin +++ b/core/os/os_openbsd.odin @@ -125,10 +125,6 @@ O_EXCL :: 0x00800 O_NOCTTY :: 0x08000 O_CLOEXEC :: 0x10000 -SEEK_SET :: 0 -SEEK_CUR :: 1 -SEEK_END :: 2 - RTLD_LAZY :: 0x001 RTLD_NOW :: 0x002 RTLD_LOCAL :: 0x000