comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Directory Operations
Date: Tue, 4 Nov 2008 15:44:31 +0100
Date: 2008-11-04T15:44:31+01:00	[thread overview]
Message-ID: <r816awr17u2u.qbtmad8jvn1f$.dlg@40tude.net> (raw)
In-Reply-To: e6361d57-d505-433f-a031-dd9c90961c98@c22g2000prc.googlegroups.com

On Tue, 4 Nov 2008 04:57:17 -0800 (PST), AndreiK wrote:

> On 3 яПНяПНяПНяПН, 19:33, "Dmitry A. Kazakov" <mail...@dmitry-kazakov.de>
> wrote:
> 
>> 2. Should you keep it non-Ada, then
>>
>> 2.a. how is this supposed to work?
>> 2.b. Where is the string allocated?
>> 2.c. Who will dispose it? When?
>> 2.d. What happens when called from multiple threads?
> 
> Yes I have to keep it in non-Ada, more exact I have to use it in the
> "NI LabVIEW"
> 2.a The LabVIEW calls the functions from DLL.
> 2.b,c LabVIEW allocates the string.
> 2.d --- I don't now

In this case it should be something like this. LabVIEW passes a buffer to
Ada (Path, equivalent to char *), and the length of the buffer (Length).
Then

with Ada.Characters.Latin_1;
with Ada.Directories;         use Ada.Directories;
with Interfaces.C;            use Interfaces.C;
with Interfaces.C.Strings;    use Interfaces.C.Strings;

procedure Pwd (Path : chars_ptr; Length : size_t) is
   Result : constant String := Current_Directory &
Ada.Characters.Latin_1.NUL;
begin
   if Result'Length > Length then
     ... -- What do you do when the buffer is too short?
   else
      Update (Path, 0, Result, False);
   end if;
end Pwd;

From C it is called like:

{
   char buffer [1024];

   pwd (buffer, sizeof (buffer));
   ...
}

However, you should really refer to LabVIEW documentation regarding the way
it passes strings around. Once you know it, you can interface Ada. The code
above is merely a wild guess about how the interface might look like.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de



  reply	other threads:[~2008-11-04 14:44 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-03 16:27 Directory Operations andrei.krivoshei
2008-11-03 17:33 ` Dmitry A. Kazakov
2008-11-04 12:57   ` AndreiK
2008-11-04 14:44     ` Dmitry A. Kazakov [this message]
2008-11-04 13:52 ` AndreiK
replies disabled

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