From: gisle@krake.ii.uib.no (Gisle S{lensminde)
Subject: Re: Reading environment variables in ADA?
Date: 1998/09/17
Date: 1998-09-17T00:00:00+00:00 [thread overview]
Message-ID: <slrn702qlt.f3k.gisle@krake.ii.uib.no> (raw)
In-Reply-To: 6tdl75$qs6$2@nyheter.chalmers.se
In article <6tdl75$qs6$2@nyheter.chalmers.se>, Stefan Lingdell wrote:
>How do you read environment variables in ADA? I'm
>programming under UNIX (SunOS) if that makes any
>difference.
>
>Thanks,
>Stefan
>
There is packages to access environment variables and other OS things.
Since this is a posix feature, you can use the florist package, If have
thought to use a lot of OS features, that is a good idea. If not, you
can use the C interface. The program under reads the HOME
environment variable, and demonstrates how the C interface can be used
for this. I have tested it for solaris/gnat, but should work on all
Unix systems. If you use other compilers than GNAT, you maybe must
link with the C library.
The example:
with Interfaces.C.Strings;
use type Interfaces.C.Strings.Chars_Ptr;
with Ada.Text_IO; use Ada.Text_IO;
procedure env is
package Cstr renames Interfaces.C.strings;
function Getenv(Name : Cstr.Chars_Ptr) return Cstr.Chars_Ptr;
pragma Import(C, Getenv);
Var_Name, Result : Cstr.Chars_Ptr;
begin
Var_Name := Cstr.New_String("HOME");
Result := Getenv(Var_Name);
Cstr.Free(Var_Name);
if Result /= Cstr.Null_Ptr then
Put_Line(Cstr.Value(Result));
end if;
end;
--
------------------------------------------------------------------------
Gisle S�lensminde Tlf: 55 34 07 63
Eliasmarken 16
5031 Laksev�g epost: gisle@ii.uib.no
UNIX is user friendly. It's just selective about who its friends are.
------------------------------------------------------------------------
next prev parent reply other threads:[~1998-09-17 0:00 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
1998-09-12 0:00 Reading environment variables in ADA? Stefan Lingdell
1998-09-12 0:00 ` David C. Hoos, Sr
1998-09-13 0:00 ` Steven Hovater
1998-09-17 0:00 ` Gisle S{lensminde [this message]
1998-10-06 0:00 ` Matthew Heaney
1998-10-06 0:00 ` dewarr
1998-10-06 0:00 ` Robert I. Eachus
1998-10-07 0:00 ` dewarr
1998-10-07 0:00 ` Robert I. Eachus
1998-10-13 0:00 ` Simon Wright
1998-09-17 0:00 ` Matthew Heaney
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox