Browse Source

Minor improvements to io and os

gingerBill 3 years ago
parent
commit
5d190b15d7
6 changed files with 6 additions and 20 deletions
  1. 2 7
      core/io/io.odin
  2. 4 0
      core/os/os.odin
  3. 0 3
      core/os/os_darwin.odin
  4. 0 3
      core/os/os_freebsd.odin
  5. 0 3
      core/os/os_linux.odin
  6. 0 4
      core/os/os_openbsd.odin

+ 2 - 7
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)

+ 4 - 0
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)
 }

+ 0 - 3
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

+ 0 - 3
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

+ 0 - 3
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

+ 0 - 4
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