Use fstat on os2.File directly

This commit is contained in:
gingerBill
2024-07-14 14:51:22 +01:00
parent d1450e3d88
commit 3d38f14202
5 changed files with 19 additions and 19 deletions
+2
View File
@@ -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"
}
+1 -1
View File
@@ -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
+10 -15
View File
@@ -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 {
+1
View File
@@ -151,6 +151,7 @@ _new_file :: proc(handle: uintptr, name: string) -> ^File {
data = f,
procedure = _file_stream_proc,
}
f.fstat = _fstat
return f
}
+5 -3
View File
@@ -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)