Browse Source

Use RTTI to get the `error_string` for Windows

gingerBill 1 year ago
parent
commit
03e90bf924
1 changed files with 10 additions and 0 deletions
  1. 10 0
      core/os/os2/errors_windows.odin

+ 10 - 0
core/os/os2/errors_windows.odin

@@ -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 ""