> On second thought, this version is better.  The previous version doesn't
> give you any way of differentiating between an undefined env var, and a
> defined env var that happens to have a zero-length string as its value.
> function getenv (Name : String)
>    return Interfaces.C.Strings.Chars_Ptr is   ...

> Matthew Heaney's solution works if the environment variable exists,
> but raises an exception if it does not.  I offer this refinement of
> Matthew's solution, where the exception is raised, but with
> information supplied which quickly pinpoints the cause of the
> exception.

I disagree with both of you.  I think the best solution is to start with
the GNAT package Ada.Command_Line.Environment, and if necessary, modify it
to do what you want.  It is covered by the "special exception" to the
GPL.  Why start over on a problem that has been solved?

The following program has output identical to ksh printenv :

with Ada.Command_Line.Environment;
with Ada.Text_IO;

procedure CL_Test is

  for I in 1 .. Ada.Command_Line.Environment.Environment_Count loop
    Ada.Text_IO.Put_Line (Ada.Command_Line.Environment.Environment_Value (I));
  end loop;
end CL_Test;