Skip to content

Environment_Variables#

The package Environment_Variables allows a program to read or modify environment variables. Environment variables are name-value pairs, where both the name and value are strings. The definition of what constitutes an environment variable, and the meaning of the name and value, are implementation defined.

package Ada.Environment_Variables
   with Preelaborate, Nonblocking, Global => in out synchronized is

   function Value (Name: String)                  return String;
   function Value (Name: String; Default: String) return String;
   function Exists(Name: String)                  return Boolean;

   procedure Set  (Name: String; Value: String);
   procedure Clear(Name: String);
   procedure Clear;

   procedure Iterate(Process: not null access procedure(Name, Value: String))
      with Allows_Exit;
end Ada.Environment_Variables;

Bounded (Run-Time) Errors

It is a bounded error to call Value if more than one environment variable exists with the given name; the possible outcomes are that:

  • One of the values is returned, and that same value is returned in subsequent calls in the absence of changes to the environment.
  • Program_Error is propagated.

Erroneous Execution

Making calls to the procedures Set or Clear concurrently with calls to any subprogram of package Environment_Variables, or to any instantiation of Iterate, results in erroneous execution.

Making calls to the procedures Set or Clear in the actual subprogram corresponding to the Process parameter of Iterate results in erroneous execution.

Wide and Wide Wide Environment Variables#

The packages Wide_Environment_Variables and Wide_Wide_Environment_Variables allow a program to read or modify environment variables.

  • The specification of package Wide_Environment_Variables is the same as for Environment_Variables, except that each occurrence of String is replaced by Wide_String.
  • The specification of package Wide_Wide_Environment_Variables is the same as for Environment_Variables, except that each occurrence of String is replaced by Wide_Wide_String.