As @egilhh comments, the language defined approach is to use the Current_Directory
function provided by Ada.Directories
.
with Ada.Text_IO, Ada.Directories;
procedure PWD is
begin
Ada.Text_IO.Put_Line(Ada.Directories.Current_Directory);
end PWD;
As cross-platform behavior is critical to your use case, you'll need to test on representative targets. You may also want to study the corresponding Ada.Directories
implementations. Use gnatkr
to determine the relevant file names. Given an environment variable named ADA_INC
that points to your adainclude
directory,
export ADA_INC=${ADA_HOME}/lib/gcc/…/adainclude
the following commands should let you view the relevant sources:
view $ADA_INC/$(gnatkr Ada.Directories.ads)
view $ADA_INC/$(gnatkr Ada.Directories.adb)
Note that Current_Directory
imports a C
function that is compiled for each supported platform and installed with the distribution. In contrast, Containing_Directory
handles Windows as a special case explicitly.
Finally, you can implement any of the cited approaches by importing a suitable function or by invoking Spawn
and Expect
, as shown in Gem #54: Scripting Capabilities in GNAT (Part 2)