Tue, 20 Apr 1999 01:06:32 -0700
Hello team members!
I have subscribed this list some times ago and now this is my first
contribution to it.
Until now I have programmed in Ada83 and needed some non-portable
packages to access command line arguments and environment variables.
Now I have an Ada95 compiler (gnat) on my new Linux machine. The
Ada95 standard contains a package Ada.Command_Line which gives my
programs access to command line arguments - but not to environment
I did not found any way to give my programs access to these
variables. Have I overlooked something or is there no way?
I tried to interface to the C function getenv. The interface seems
to work but getenv only returns my input (the name of the variable
but not their contents):
function Get_Environment_Variable (Name: String) return String is
-- getenv - get an environment variable
-- #include <stdlib.h>
-- char *getenv(const char *name);
-- The getenv() function searches the environment list for a
-- string that matches the string pointed to by name. The
-- strings are of the form name = value.
package C renames Interfaces.C;
function Getenv (Name: in C.char_array) return C.char_array;
pragma Import (C, Getenv, "getenv");
C_Name: C.Char_Array (0 .. Name'Length);
C_Name := To_C (Name);
Env_Length := Getenv (C_Name)'Length - 1;
C_Env: C.Char_Array (0 .. C.size_t (Env_Length));
C_Env (0) := C.nul;
C_Env := Getenv (C_Name);
return To_Ada (C_Env);
(The function is somewhat complicated but simply typing
return To_Ada (C_Env (To_C (Name)));
produces a "segmentation fault".)
Has anybody a solution for my problem?
Sorry for my broken english :)
Steffen Bretz Tel +49-561-7392805
Rothenditmolder Str. 23 mailto:[log in to unmask]