Here I Am!
This is an Ada wrapper applied to the Where Am I? library by Gregory Pakosz. As with the original C, this allows for easily locating where the running executable or module is stored in the filesystem.
Note that this functionality is not something you can do with the Ada standard library!
The Command_Name
subprogram in Ada.Command_Line
will only get you the
command used to invoke the executable, which might be a symlink and/or might
have had a platform-specific $PATH
used to find it. The Current_Directory
and Containing_Directory
subprograms in Ada.Directories
will only get you
the current working directory. That may be completely different from where the
executable is located if an absolute or relative path was supplied with the
command or, again, a platform-specific $PATH
was involved.
Of the options in the standard library the most reliable one would be to use
Ada.Environment_Variables
and process each possible platform-specific $PATH
manually. But that still wouldn't resolve any symlinks or other shortcut files.
Building and Installation
If this was a dynamic library then the function to locate the current module would always return the location of that shared object. On the other hand if this was a static library then it wouldn't be possible to compile as part of a dynamic libary.
Thus, to use this you should instead just copy the contents of src
wholesale
to a suitable spot in your own project.
The tests.gpr
project file can be used to build some very basic sanity checks
if desired.
Credits and Licensing
Ada wrapper code written by Jedidiah Barber and released into the public domain
as per unlicense.txt
.
C code written by Gregory Pakosz and licensed under the WTFPL which lets you do whatever you want, so it's basically public domain as well.