mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Use fstat on os2.File directly
This commit is contained in:
@@ -22,6 +22,7 @@ General_Error :: enum u32 {
|
|||||||
Invalid_File,
|
Invalid_File,
|
||||||
Invalid_Dir,
|
Invalid_Dir,
|
||||||
Invalid_Path,
|
Invalid_Path,
|
||||||
|
Invalid_Callback,
|
||||||
|
|
||||||
Pattern_Has_Separator,
|
Pattern_Has_Separator,
|
||||||
|
|
||||||
@@ -64,6 +65,7 @@ error_string :: proc(ferr: Error) -> string {
|
|||||||
case .Invalid_File: return "invalid file"
|
case .Invalid_File: return "invalid file"
|
||||||
case .Invalid_Dir: return "invalid directory"
|
case .Invalid_Dir: return "invalid directory"
|
||||||
case .Invalid_Path: return "invalid path"
|
case .Invalid_Path: return "invalid path"
|
||||||
|
case .Invalid_Callback: return "invalid callback"
|
||||||
case .Unsupported: return "unsupported"
|
case .Unsupported: return "unsupported"
|
||||||
case .Pattern_Has_Separator: return "pattern has separator"
|
case .Pattern_Has_Separator: return "pattern has separator"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import "base:runtime"
|
|||||||
File :: struct {
|
File :: struct {
|
||||||
impl: _File,
|
impl: _File,
|
||||||
stream: io.Stream,
|
stream: io.Stream,
|
||||||
user_fstat: Fstat_Callback,
|
fstat: Fstat_Callback,
|
||||||
}
|
}
|
||||||
|
|
||||||
File_Mode :: distinct u32
|
File_Mode :: distinct u32
|
||||||
|
|||||||
+10
-15
@@ -90,22 +90,17 @@ _open :: proc(name: string, flags: File_Flags, perm: File_Mode) -> (f: ^File, er
|
|||||||
|
|
||||||
_new_file :: proc(fd: uintptr, _: string = "") -> ^File {
|
_new_file :: proc(fd: uintptr, _: string = "") -> ^File {
|
||||||
file := new(File, file_allocator())
|
file := new(File, file_allocator())
|
||||||
_construct_file(file, fd, "")
|
file.impl = {
|
||||||
return file
|
fd = linux.Fd(fd),
|
||||||
}
|
allocator = file_allocator(),
|
||||||
|
name = _get_full_path(file.impl.fd, file.impl.allocator),
|
||||||
_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.stream = {
|
||||||
|
data = file,
|
||||||
|
procedure = _file_stream_proc,
|
||||||
|
}
|
||||||
|
file.fstat = _fstat
|
||||||
|
return file
|
||||||
}
|
}
|
||||||
|
|
||||||
_destroy :: proc(f: ^File) -> Error {
|
_destroy :: proc(f: ^File) -> Error {
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ _new_file :: proc(handle: uintptr, name: string) -> ^File {
|
|||||||
data = f,
|
data = f,
|
||||||
procedure = _file_stream_proc,
|
procedure = _file_stream_proc,
|
||||||
}
|
}
|
||||||
|
f.fstat = _fstat
|
||||||
|
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,10 +29,12 @@ file_info_delete :: proc(fi: File_Info, allocator: runtime.Allocator) {
|
|||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
fstat :: proc(f: ^File, allocator: runtime.Allocator) -> (File_Info, Error) {
|
fstat :: proc(f: ^File, allocator: runtime.Allocator) -> (File_Info, Error) {
|
||||||
if f != nil && f.user_fstat != nil {
|
if f == nil {
|
||||||
return f->user_fstat(allocator)
|
return {}, nil
|
||||||
|
} else if f.fstat != nil {
|
||||||
|
return f->fstat(allocator)
|
||||||
}
|
}
|
||||||
return _fstat(f, allocator)
|
return {}, .Invalid_Callback
|
||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
|
|||||||
Reference in New Issue
Block a user