diff --git a/core/os/os2/errors.odin b/core/os/os2/errors.odin index 51d8314b4..8961bf599 100644 --- a/core/os/os2/errors.odin +++ b/core/os/os2/errors.odin @@ -22,6 +22,7 @@ General_Error :: enum u32 { Invalid_File, Invalid_Dir, Invalid_Path, + Invalid_Callback, Pattern_Has_Separator, @@ -64,6 +65,7 @@ error_string :: proc(ferr: Error) -> string { case .Invalid_File: return "invalid file" case .Invalid_Dir: return "invalid directory" case .Invalid_Path: return "invalid path" + case .Invalid_Callback: return "invalid callback" case .Unsupported: return "unsupported" case .Pattern_Has_Separator: return "pattern has separator" } diff --git a/core/os/os2/file.odin b/core/os/os2/file.odin index 236423163..dc618db37 100644 --- a/core/os/os2/file.odin +++ b/core/os/os2/file.odin @@ -7,7 +7,7 @@ import "base:runtime" File :: struct { impl: _File, stream: io.Stream, - user_fstat: Fstat_Callback, + fstat: Fstat_Callback, } File_Mode :: distinct u32 diff --git a/core/os/os2/file_linux.odin b/core/os/os2/file_linux.odin index 8e7db9751..eaded51c9 100644 --- a/core/os/os2/file_linux.odin +++ b/core/os/os2/file_linux.odin @@ -90,22 +90,17 @@ _open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (f: ^File, er _new_file :: proc(fd: uintptr, _: string = "") -> ^File { file := new(File, file_allocator()) - _construct_file(file, fd, "") - return file -} - -_construct_file :: proc(file: ^File, fd: uintptr, _: string = "") { - file^ = { - impl = { - fd = linux.Fd(fd), - allocator = file_allocator(), - name = _get_full_path(file.impl.fd, file.impl.allocator), - }, - stream = { - data = file, - procedure = _file_stream_proc, - }, + file.impl = { + fd = linux.Fd(fd), + allocator = file_allocator(), + name = _get_full_path(file.impl.fd, file.impl.allocator), } + file.stream = { + data = file, + procedure = _file_stream_proc, + } + file.fstat = _fstat + return file } _destroy :: proc(f: ^File) -> Error { diff --git a/core/os/os2/file_windows.odin b/core/os/os2/file_windows.odin index b88ee8a69..8953edafb 100644 --- a/core/os/os2/file_windows.odin +++ b/core/os/os2/file_windows.odin @@ -151,6 +151,7 @@ _new_file :: proc(handle: uintptr, name: string) -> ^File { data = f, procedure = _file_stream_proc, } + f.fstat = _fstat return f } diff --git a/core/os/os2/stat.odin b/core/os/os2/stat.odin index f79ad9165..1e7f9d225 100644 --- a/core/os/os2/stat.odin +++ b/core/os/os2/stat.odin @@ -29,10 +29,12 @@ file_info_delete :: proc(fi: File_Info, allocator: runtime.Allocator) { @(require_results) fstat :: proc(f: ^File, allocator: runtime.Allocator) -> (File_Info, Error) { - if f != nil && f.user_fstat != nil { - return f->user_fstat(allocator) + if f == nil { + return {}, nil + } else if f.fstat != nil { + return f->fstat(allocator) } - return _fstat(f, allocator) + return {}, .Invalid_Callback } @(require_results)