This is an appendix to Understanding Unix/Linux
Programming
written for people interested in Ada programming on POSIX
systems.
pwdmkdirYou create a directory with procedure
Create_Directory:
package POSIX.Files is
[...]
procedure Create_Directory
(Pathname : in POSIX.Pathname;
Permission : in POSIX.Permissions.Permission_Set);
[...]
end POSIX.Files;
rmdirSimilarly you remove a directory with procedure
Remove_Directory:
package POSIX.Files is [...] procedure Remove_Directory (Pathname : in POSIX.Pathname); [...] end POSIX.Files;
rmYou remove a file with procedure
Unlink:
package POSIX.Files is [...] procedure Unlink (Pathname : in POSIX.Pathname); [...] end POSIX.Files;
lnYou create a new link to file with procedure
Link:
package POSIX.Files is
[...]
procedure Link
(Old_Pathname : in POSIX.Pathname;
New_Pathname : in POSIX.Pathname);
[...]
end POSIX.Files;
mvYou change the name or location of a file with
procedure Rename:
package POSIX.Files is
[...]
procedure Rename
(Old_Pathname : in POSIX.Pathname;
New_Pathname : in POSIX.Pathname);
[...]
end POSIX.Files;
cdYou change the working directory of your shell with the command
cd. Similarly you can change the working
directory of a running process by calling procedure
Change_Working_Directory:
package POSIX.Process_Environment is
[...]
procedure Change_Working_Directory
(Directory_Name : in POSIX.Pathname);
[...]
end POSIX.Process_Environment;
We can use function Get_Working_Directory
to get the current working directory of our process:
package POSIX.Process_Environment is [...] function Get_Working_Directory return POSIX.Pathname; [...] end POSIX.Process_Environment;
This makes it very simple to implement the command pwd.
Here is a first draft: spwd.adb
We compile it and compare it with the system version:
% gnatmake -P spwd [...] % pwd; /bin/pwd; ./spwd /home/sparre/temp/Posix_in_Ada/04 /home/sparre/Undervisning/CEUS/CA+OS/Posix_in_Ada/04 /home/sparre/Undervisning/CEUS/CA+OS/Posix_in_Ada/04 % which pwd pwd: shell built-in command
We see how the shell built-in version shows one thing (the sequence
of directory names I have cd
ed through; including symbolic
links), while the system program and our own program agree and show
the actual path to the directory.
Modern unixes (for example Linux and OpenSolaris) can be
configured to join several disks as one big file system, so we are
not really stuck with the third approach
.
The POSIX/C functions symlink and readlink do
not have corresponding operations in POSIX/Ada. If you want to work on
symbolic links, you have to import these functions from POSIX/C instead of
using native POSIX/Ada functions.
Go to next chapter.
Understanding Unix/Linux Programming, Bruce Molay,
ISBN 0-13-008396-8.