Use RTTI to get the error_string for Windows

This commit is contained in:
gingerBill
2024-07-16 12:26:24 +01:00
parent 8d70a264ab
commit 03e90bf924

View File

@@ -1,6 +1,8 @@
//+private
package os2
import "base:runtime"
import "core:slice"
import win32 "core:sys/windows"
_error_string :: proc(errno: i32) -> string {
@@ -8,6 +10,14 @@ _error_string :: proc(errno: i32) -> string {
if e == 0 {
return ""
}
err := runtime.Type_Info_Enum_Value(e)
ti := &runtime.type_info_base(type_info_of(win32.System_Error)).variant.(runtime.Type_Info_Enum)
if idx, ok := slice.binary_search(ti.values, err); ok {
return ti.names[idx]
}
// TODO(bill): _error_string for windows
// FormatMessageW
return ""