From 2a212a755659459c945ce0aec80ad73c690e76d1 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Thu, 8 Jun 2023 17:00:38 +0100 Subject: [PATCH] Put stream into the impl --- core/os/os2/file.odin | 28 +++++++++++++--------------- core/os/os2/file_linux.odin | 4 +++- core/os/os2/file_stream.odin | 4 ++-- core/os/os2/file_windows.odin | 4 +++- 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/core/os/os2/file.odin b/core/os/os2/file.odin index 6c1cef89f..4113675ca 100644 --- a/core/os/os2/file.odin +++ b/core/os/os2/file.odin @@ -5,8 +5,7 @@ import "core:time" import "core:runtime" File :: struct { - impl: _File, - stream: io.Stream, + impl: _File, } File_Mode :: distinct u32 @@ -72,40 +71,39 @@ name :: proc(f: ^File) -> string { } close :: proc(f: ^File) -> Error { - return io.close(f.stream) + return io.close(f.impl.stream) } seek :: proc(f: ^File, offset: i64, whence: io.Seek_From) -> (ret: i64, err: Error) { - return io.seek(f.stream, offset, whence) + return io.seek(f.impl.stream, offset, whence) } read :: proc(f: ^File, p: []byte) -> (n: int, err: Error) { - return io.read(f.stream, p) + return io.read(f.impl.stream, p) } read_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) { - return io.read_at(f.stream, p, offset) + return io.read_at(f.impl.stream, p, offset) } write :: proc(f: ^File, p: []byte) -> (n: int, err: Error) { - return io.write(f.stream, p) + return io.write(f.impl.stream, p) } write_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) { - return io.write_at(f.stream, p, offset) + return io.write_at(f.impl.stream, p, offset) } file_size :: proc(f: ^File) -> (n: i64, err: Error) { - return io.size(f.stream) -} - - -sync :: proc(f: ^File) -> Error { - return _sync(f) + return io.size(f.impl.stream) } flush :: proc(f: ^File) -> Error { - return io.flush(f.stream) + return io.flush(f.impl.stream) +} + +sync :: proc(f: ^File) -> Error { + return _sync(f) } truncate :: proc(f: ^File, size: i64) -> Error { diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin index a43c1aadf..8df19614f 100644 --- a/core/os/os2/file_linux.odin +++ b/core/os/os2/file_linux.odin @@ -33,6 +33,8 @@ _File :: struct { name: string, fd: int, allocator: runtime.Allocator, + + stream: io.Stream, } _file_allocator :: proc() -> runtime.Allocator { @@ -73,7 +75,7 @@ _new_file :: proc(fd: uintptr, _: string) -> ^File { file.impl.fd = int(fd) file.impl.allocator = _file_allocator() file.impl.name = _get_full_path(file.impl.fd, file.impl.allocator) - file.stream = { + file.impl.stream = { data = file, procedure = _file_stream_proc, } diff --git a/core/os/os2/file_stream.odin b/core/os/os2/file_stream.odin index 84176928d..da1e3344f 100644 --- a/core/os/os2/file_stream.odin +++ b/core/os/os2/file_stream.odin @@ -4,8 +4,8 @@ import "core:io" to_stream :: proc(f: ^File) -> (s: io.Stream) { if f != nil { - assert(f.stream.procedure != nil) - s = f.stream + assert(f.impl.stream.procedure != nil) + s = f.impl.stream } return } diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin index 50938d92a..5ca3eded8 100644 --- a/core/os/os2/file_windows.odin +++ b/core/os/os2/file_windows.odin @@ -38,6 +38,8 @@ _File :: struct { wname: win32.wstring, kind: _File_Kind, + stream: io.Stream, + allocator: runtime.Allocator, rw_mutex: sync.RW_Mutex, // read write calls @@ -144,7 +146,7 @@ _new_file :: proc(handle: uintptr, name: string) -> ^File { } f.impl.kind = kind - f.stream = { + f.impl.stream = { data = f, procedure = _file_stream_proc, }