From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_MSGID, PDS_OTHER_BAD_TLD autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a4c01e243163facf,start X-Google-Attributes: gid103376,public From: seibert@monkfish.nosc.mil (Jerome D. Seibert) Subject: C File Descriptors in Ada95 Date: 1996/07/19 Message-ID: <1996Jul19.225520.22396@nosc.mil>#1/1 X-Deja-AN: 168997281 sender: news@nosc.mil organization: NCCOSC RDT&E Division, San Diego, CA newsgroups: comp.lang.ada Date: 1996-07-19T00:00:00+00:00 List-Id: 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;