comp.lang.ada
 help / color / mirror / Atom feed
From: Jeffrey Carter <spam.jrcarter.not@spam.not.acm.org>
Subject: Re: Read Windows login username in Ada 95
Date: Wed, 09 Nov 2011 14:52:11 -0700
Date: 2011-11-09T14:52:11-07:00	[thread overview]
Message-ID: <j9esnb$2tv$1@tornado.tornevall.net> (raw)
In-Reply-To: <268750.2183.1320871677246.JavaMail.geo-discussion-forums@yqan20>

On 11/09/2011 01:47 PM, Rego, P. wrote:
>
> function GetUsername return String is
>     function GetEnv (Variable : String) return Interfaces.C.Strings.chars_ptr;

This no doubt expects a NUL-terminated string. I would use Char_Array for the 
parameter and To_C to convert an Ada string passed to it.

>     pragma Import (C, GetEnv, "getenv");
>
>     Command : constant String := "USERNAME";
>     Answer_Ptr : constant Interfaces.C.Strings.chars_ptr := GetEnv (Command);

You're not giving it a NUL-terminated string.

>     Answer : constant String := Interfaces.C.Strings.Value (Answer_Ptr);
> begin
>     return Answer;

Who is responsible for freeing Answer_Ptr?

> end GetUsername;

As Obry suggested, Ada.Environment_Variables is an all-Ada way to do this.

-- 
Jeff Carter
"Alms for an ex-leper!"
Monty Python's Life of Brian
75



  parent reply	other threads:[~2011-11-09 21:52 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-09  1:19 Read Windows login username in Ada 95 Rego, P.
2011-11-09  5:05 ` tmoran
2011-11-10  0:02   ` Adam Beneschan
2011-11-10  1:17     ` Rego, P.
2011-11-09 10:44 ` Pascal Obry
2011-11-09 20:47 ` Rego, P.
2011-11-09 21:06   ` Pascal Obry
2011-11-10  1:16     ` Rego, P.
2011-11-09 21:52   ` Jeffrey Carter [this message]
2011-11-10  1:21     ` Rego, P.
2011-11-10  2:09       ` tmoran
2011-11-10 18:26       ` Jeffrey Carter
2011-11-10 23:13         ` Pascal Obry
2011-11-12 14:21           ` Rego, P.
2011-11-10 23:13         ` Pascal Obry
replies disabled

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