comp.lang.ada
 help / color / mirror / Atom feed
* ada/c if - putenv?
@ 2000-03-07  0:00 Al Johnston
  2000-03-07  0:00 ` Jeff Carter
  2000-03-14  0:00 ` Nick Roberts
  0 siblings, 2 replies; 5+ messages in thread
From: Al Johnston @ 2000-03-07  0:00 UTC (permalink / raw)


I am try to learn ada->c interfacing.

Will someone please explain why the following program does not
work?.  If I set the env manually and remove the call to putenv
from the test case, the call to getenv works okay... but when
I let the test code call putenv, not only does the getenv call
not return the value given it by the putenv call, but it does
not even get the old (manually set) value...

what am I missing (gnat 3.12 on a linux RH6.1 x86)

tnx,

-al

with euanos;
with text_io;

procedure test is
begin
  euanos.PutEnv("ASJ=hi");
  text_io.put_line(" ==>" & euanos.GetEnv("ASJ") & "<==");
end test;

with interfaces.c.strings;

package EUANOS  is

  --
---------------------------------------------------------------------------

  -- Name: EUANOS (eise-utilities/ada/native/op-system
  --
  --
---------------------------------------------------------------------------

  EUANOS_PutEnv_Failed : exception;


  procedure PutEnv(Sym : String);


  function GetEnv(Sym : String) return String;

end EUANOS;

with interfaces.c.strings;

package body EUANOS is

  --
---------------------------------------------------------------------------

  -- Name: EUANOS (eise utilities/ada/native/op-system
  --
  --
---------------------------------------------------------------------------

  package EUANOS_CIf is

    --
-------------------------------------------------------------------------

    -- see man putenv(3V)
    --
    -- int putenv(const char *string);
    --
    function putenv(Sym : interfaces.c.strings.Chars_Ptr)
             return interfaces.c.Int;
    pragma import(c,putenv,"putenv");
    --
-------------------------------------------------------------------------



    --
-------------------------------------------------------------------------

    -- see man getenv(3V)
    --
    -- char *getenv(const char *name);
    --
    function getenv(sym : interfaces.c.strings.Chars_Ptr)
             return interfaces.c.strings.Chars_Ptr;
    pragma import(c,getenv,"getenv");
    --
-------------------------------------------------------------------------

  end EUANOS_CIf;


  procedure PutEnv(Sym : String) is
    Arg    : interfaces.c.strings.Chars_Ptr;
    Result : interfaces.c.Int;
  begin
    Arg    := interfaces.c.strings.New_String(Sym);
    Result := EUANOS_CIf.putenv(Arg);
    interfaces.c.strings.Free(Arg);
    if (integer(Result) /= 0) then
      raise EUANOS_PutEnv_Failed;
    end if;
  end PutEnv;

  function GetEnv(Sym : String) return String is
    Arg    : interfaces.c.strings.Chars_Ptr;
    Result : interfaces.c.strings.Chars_Ptr;
  begin
    Arg    := interfaces.c.strings.New_String(Sym);
    Result := EUANOS_CIf.getenv(Arg);
    interfaces.c.strings.Free(Arg);
    if interfaces.c.strings."="(Result,interfaces.c.strings.Null_Ptr)
then
      return "-";
    else
      return interfaces.c.strings.Value(Result);
    end if;
  end GetEnv;

end EUANOS;






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2000-03-14  0:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-07  0:00 ada/c if - putenv? Al Johnston
2000-03-07  0:00 ` Jeff Carter
2000-03-08  0:00   ` Geoff Bull
2000-03-07  0:00     ` Al Johnston
2000-03-14  0:00 ` Nick Roberts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox