Subject: | |
From: | |
Reply To: | |
Date: | Tue, 20 Apr 1999 01:06:32 -0700 |
Content-Type: | text/plain |
Parts/Attachments: |
|
|
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
variables.
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
-- NAME:
-- getenv - get an environment variable
-- SYNOPSIS:
-- #include <stdlib.h>
-- char *getenv(const char *name);
-- DESCRIPTION:
-- 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);
Env_Length: Natural;
use C;
begin
C_Name := To_C (Name);
Env_Length := Getenv (C_Name)'Length - 1;
declare
C_Env: C.Char_Array (0 .. C.size_t (Env_Length));
begin
C_Env (0) := C.nul;
C_Env := Getenv (C_Name);
return To_Ada (C_Env);
end;
end;
(The function is somewhat complicated but simply typing
...
begin
return To_Ada (C_Env (To_C (Name)));
end;
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]
34117 Kassel
Germany
|
|
|