mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-02 04:38:16 +00:00
Expect stream as a field directly on os2.File
This commit is contained in:
@@ -6,6 +6,7 @@ import "base:runtime"
|
|||||||
|
|
||||||
File :: struct {
|
File :: struct {
|
||||||
impl: _File,
|
impl: _File,
|
||||||
|
stream: io.Stream,
|
||||||
}
|
}
|
||||||
|
|
||||||
File_Mode :: distinct u32
|
File_Mode :: distinct u32
|
||||||
@@ -72,56 +73,56 @@ name :: proc(f: ^File) -> string {
|
|||||||
|
|
||||||
close :: proc(f: ^File) -> Error {
|
close :: proc(f: ^File) -> Error {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.close(f.impl.stream)
|
return io.close(f.stream)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
seek :: proc(f: ^File, offset: i64, whence: io.Seek_From) -> (ret: i64, err: Error) {
|
seek :: proc(f: ^File, offset: i64, whence: io.Seek_From) -> (ret: i64, err: Error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.seek(f.impl.stream, offset, whence)
|
return io.seek(f.stream, offset, whence)
|
||||||
}
|
}
|
||||||
return 0, .Invalid_File
|
return 0, .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
read :: proc(f: ^File, p: []byte) -> (n: int, err: Error) {
|
read :: proc(f: ^File, p: []byte) -> (n: int, err: Error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.read(f.impl.stream, p)
|
return io.read(f.stream, p)
|
||||||
}
|
}
|
||||||
return 0, .Invalid_File
|
return 0, .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
read_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) {
|
read_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.read_at(f.impl.stream, p, offset)
|
return io.read_at(f.stream, p, offset)
|
||||||
}
|
}
|
||||||
return 0, .Invalid_File
|
return 0, .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
write :: proc(f: ^File, p: []byte) -> (n: int, err: Error) {
|
write :: proc(f: ^File, p: []byte) -> (n: int, err: Error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.write(f.impl.stream, p)
|
return io.write(f.stream, p)
|
||||||
}
|
}
|
||||||
return 0, .Invalid_File
|
return 0, .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
write_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) {
|
write_at :: proc(f: ^File, p: []byte, offset: i64) -> (n: int, err: Error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.write_at(f.impl.stream, p, offset)
|
return io.write_at(f.stream, p, offset)
|
||||||
}
|
}
|
||||||
return 0, .Invalid_File
|
return 0, .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
file_size :: proc(f: ^File) -> (n: i64, err: Error) {
|
file_size :: proc(f: ^File) -> (n: i64, err: Error) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.size(f.impl.stream)
|
return io.size(f.stream)
|
||||||
}
|
}
|
||||||
return 0, .Invalid_File
|
return 0, .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
flush :: proc(f: ^File) -> Error {
|
flush :: proc(f: ^File) -> Error {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
return io.flush(f.impl.stream)
|
return io.flush(f.stream)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,8 +33,6 @@ _File :: struct {
|
|||||||
name: string,
|
name: string,
|
||||||
fd: int,
|
fd: int,
|
||||||
allocator: runtime.Allocator,
|
allocator: runtime.Allocator,
|
||||||
|
|
||||||
stream: io.Stream,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_file_allocator :: proc() -> runtime.Allocator {
|
_file_allocator :: proc() -> runtime.Allocator {
|
||||||
@@ -75,7 +73,7 @@ _new_file :: proc(fd: uintptr, _: string) -> ^File {
|
|||||||
file.impl.fd = int(fd)
|
file.impl.fd = int(fd)
|
||||||
file.impl.allocator = _file_allocator()
|
file.impl.allocator = _file_allocator()
|
||||||
file.impl.name = _get_full_path(file.impl.fd, file.impl.allocator)
|
file.impl.name = _get_full_path(file.impl.fd, file.impl.allocator)
|
||||||
file.impl.stream = {
|
file.stream = {
|
||||||
data = file,
|
data = file,
|
||||||
procedure = _file_stream_proc,
|
procedure = _file_stream_proc,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import "core:io"
|
|||||||
|
|
||||||
to_stream :: proc(f: ^File) -> (s: io.Stream) {
|
to_stream :: proc(f: ^File) -> (s: io.Stream) {
|
||||||
if f != nil {
|
if f != nil {
|
||||||
assert(f.impl.stream.procedure != nil)
|
assert(f.stream.procedure != nil)
|
||||||
s = f.impl.stream
|
s = f.stream
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -73,8 +73,6 @@ _File :: struct {
|
|||||||
wname: win32.wstring,
|
wname: win32.wstring,
|
||||||
kind: _File_Kind,
|
kind: _File_Kind,
|
||||||
|
|
||||||
stream: io.Stream,
|
|
||||||
|
|
||||||
allocator: runtime.Allocator,
|
allocator: runtime.Allocator,
|
||||||
|
|
||||||
rw_mutex: sync.RW_Mutex, // read write calls
|
rw_mutex: sync.RW_Mutex, // read write calls
|
||||||
@@ -181,7 +179,7 @@ _new_file :: proc(handle: uintptr, name: string) -> ^File {
|
|||||||
}
|
}
|
||||||
f.impl.kind = kind
|
f.impl.kind = kind
|
||||||
|
|
||||||
f.impl.stream = {
|
f.stream = {
|
||||||
data = f,
|
data = f,
|
||||||
procedure = _file_stream_proc,
|
procedure = _file_stream_proc,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user