From aa322806bbf375505c9a67603768af83cc443e2d Mon Sep 17 00:00:00 2001 From: Jedidiah Barber Date: Sun, 6 Apr 2025 12:50:24 +1200 Subject: Now handles negative return codes with an exception --- src/here_i_am.adb | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'src/here_i_am.adb') diff --git a/src/here_i_am.adb b/src/here_i_am.adb index 0117fc3..879e07e 100644 --- a/src/here_i_am.adb +++ b/src/here_i_am.adb @@ -6,9 +6,14 @@ with + Ada.Assertions, Interfaces.C.Strings, System.Storage_Elements; +use type + + Interfaces.C.int; + package body Here_I_Am is @@ -46,12 +51,16 @@ package body Here_I_Am is wai_getExecutablePath (Interfaces.C.Strings.Null_Ptr, 0, Null_Pointer); Data_Buffer : aliased Interfaces.C.char_array := (1 .. Interfaces.C.size_t (Path_Length) => Interfaces.C.nul); - Ignore : constant Interfaces.C.int := wai_getExecutablePath + Code : constant Interfaces.C.int := wai_getExecutablePath (Interfaces.C.Strings.To_Chars_Ptr (Data_Buffer'Unchecked_Access), Path_Length, Null_Pointer); begin + pragma Assert (Code >= 0); return Interfaces.C.To_Ada (Data_Buffer, False); + exception + when Ada.Assertions.Assertion_Error => raise Where_Is_Error with + "wai_getExecutablePath returned int value of " & Interfaces.C.int'Image (Code); end Executable; @@ -62,12 +71,16 @@ package body Here_I_Am is wai_getModulePath (Interfaces.C.Strings.Null_Ptr, 0, Null_Pointer); Data_Buffer : aliased Interfaces.C.char_array := (1 .. Interfaces.C.size_t (Path_Length) => Interfaces.C.nul); - Ignore : constant Interfaces.C.int := wai_getModulePath + Code : constant Interfaces.C.int := wai_getModulePath (Interfaces.C.Strings.To_Chars_Ptr (Data_Buffer'Unchecked_Access), Path_Length, Null_Pointer); begin + pragma Assert (Code >= 0); return Interfaces.C.To_Ada (Data_Buffer, False); + exception + when Ada.Assertions.Assertion_Error => raise Where_Is_Error with + "wai_getModulePath returned int value of " & Interfaces.C.int'Image (Code); end Module; -- cgit