comp.lang.ada
 help / color / mirror / Atom feed
* C File Descriptors in Ada95
@ 1996-07-19  0:00 Jerome D. Seibert
  1996-07-21  0:00 ` Nasser Abbasi
  1996-07-22  0:00 ` j. doe
  0 siblings, 2 replies; 3+ messages in thread
From: Jerome D. Seibert @ 1996-07-19  0:00 UTC (permalink / raw)



I have a need to make a call to a C function from an Ada-95 procedure, and
pass an open file descriptor to the C function.

I have tried extending Ada.Text_IO and passing File.Stream to my C routine
and then dereferencing the pointer in the C code (this did not work).
I then tried performing an unchecked conversion from System.Address to
Integer'Access to convert File.Stream to an Integer access, dereference the
access pointer and passing this to my C routine as a file descriptor (int)
(this did not work either).

Any info on how I might do this would be greatly appreciated.

A simplified sample of code follows (the File parameter must already be open
for write prior to making the call to Ada.Text_IO.sendfd.sendfd):

with Ada.Unchecked_Conversion;
with System;
with Interfaces.C;

package body Ada.Text_IO.sendfd is
   package IC renames Interfaces.C;

   --  this is my C routine
   procedure sendfd (fd : IC.int);
   pragma Import (C, sendfd, "sendfd");

   --  define an integer access which will reference the file descriptor
   type FD_Ptr is access Integer;
   function UC_To_FD_Ptr is
      new Ada.Unchecked_Conversion (System.Address, FD_Ptr);

   procedure sendfd (File   : in out File_Type) is
      fd       : Integer;
   begin
      --  convert File.Stream to a file descriptor
      fd := UC_To_FD_Ptr (File.Stream).all;

      --  now call the C routine
      sendfd (IC.int (fd));
   end sendfd;
end Ada.Text_IO.sendfd;




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

end of thread, other threads:[~1996-07-22  0:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1996-07-19  0:00 C File Descriptors in Ada95 Jerome D. Seibert
1996-07-21  0:00 ` Nasser Abbasi
1996-07-22  0:00 ` j. doe

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