aboutsummaryrefslogtreecommitdiff
path: root/src/here_i_am.adb
diff options
context:
space:
mode:
authorJedidiah Barber <contact@jedbarber.id.au>2025-04-05 23:06:26 +1300
committerJedidiah Barber <contact@jedbarber.id.au>2025-04-05 23:06:26 +1300
commit10286c0b22f3111e74bf699f224a4e8061626d4c (patch)
tree172b3198153258b54aa4fd4540e7231ccfc66b7a /src/here_i_am.adb
Initial commit
Diffstat (limited to 'src/here_i_am.adb')
-rw-r--r--src/here_i_am.adb76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/here_i_am.adb b/src/here_i_am.adb
new file mode 100644
index 0000000..0117fc3
--- /dev/null
+++ b/src/here_i_am.adb
@@ -0,0 +1,76 @@
+
+
+-- Programmed by Jedidiah Barber
+-- Released into the public domain
+
+
+with
+
+ Interfaces.C.Strings,
+ System.Storage_Elements;
+
+
+package body Here_I_Am is
+
+
+ package Storage renames System.Storage_Elements;
+
+ Null_Pointer : constant Storage.Integer_Address := Storage.To_Integer (System.Null_Address);
+
+
+
+
+ function wai_getExecutablePath
+ (Buffer : in Interfaces.C.Strings.chars_ptr;
+ Length : in Interfaces.C.int;
+ Dir : in Storage.Integer_Address)
+ return Interfaces.C.int;
+ pragma Import (C, wai_getExecutablePath, "wai_getExecutablePath");
+ pragma Inline (wai_getExecutablePath);
+
+ function wai_getModulePath
+ (Buffer : in Interfaces.C.Strings.chars_ptr;
+ Length : in Interfaces.C.int;
+ Dir : in Storage.Integer_Address)
+ return Interfaces.C.int;
+ pragma Import (C, wai_getModulePath, "wai_getModulePath");
+ pragma Inline (wai_getModulePath);
+
+
+
+
+ function Executable
+ return String
+ is
+ Path_Length : constant Interfaces.C.int :=
+ 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
+ (Interfaces.C.Strings.To_Chars_Ptr (Data_Buffer'Unchecked_Access),
+ Path_Length,
+ Null_Pointer);
+ begin
+ return Interfaces.C.To_Ada (Data_Buffer, False);
+ end Executable;
+
+
+ function Module
+ return String
+ is
+ Path_Length : constant Interfaces.C.int :=
+ 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
+ (Interfaces.C.Strings.To_Chars_Ptr (Data_Buffer'Unchecked_Access),
+ Path_Length,
+ Null_Pointer);
+ begin
+ return Interfaces.C.To_Ada (Data_Buffer, False);
+ end Module;
+
+
+end Here_I_Am;
+
+