comp.lang.ada
 help / color / mirror / Atom feed
From: Poul-Erik Andreasen <poulerik@pea.dk>
Subject: binding to C:  popen
Date: Tue, 21 Feb 2006 15:37:02 +0100
Date: 2006-02-21T15:37:02+01:00	[thread overview]
Message-ID: <43fb258f$0$170$edfadb0f@dread11.news.tele.dk> (raw)

Hi

i am trying to make a biding to the C function popen, it goes like this:

with System.Address_To_Access_Conversions;
with Interfaces.C_Streams;

package Pipe_Pkg is

    subtype Command_Pipe is Interfaces.C_Streams.FILEs;

    procedure Pipe_Open (Pipe    : in out Command_Pipe;
                         Command : in  String);
private

   function To_C (Input : in String) return Interfaces.C_Streams.Chars;

end Pipe_Pkg;


package body Pipe_Pkg is


    procedure Pipe_Open
      (Pipe    : in out Command_Pipe;
       Command : in  String)
    is
       use Interfaces.C_Streams;
       function C_Popen (C_Command : Chars;
                         C_Type    : Chars) return Command_Pipe;

       pragma Import (C, C_Popen, "popen");

    begin
       Pipe := C_Popen ((To_C (Command)), To_C ("w"));
    end Pipe_Open;

    function To_C (Input : in String) return Interfaces.C_Streams.Chars 


    is
      package String_Conversion is
         new System.Address_To_Access_Conversions (String);

      String_Pointer : String_Conversion.Object_Pointer :=
                          new String'(Input & ascii.nul);
    begin
       return String_Conversion.To_Address (String_Pointer);
    end;


end Pipe_Pkg;



This ictually going as it is suppose to, but i would like set in an 
exception if the piping dosn't have succes. Acording to the C manual
popen returns null if it fails. But how do i test on that in the FILEs type?







             reply	other threads:[~2006-02-21 14:37 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-02-21 14:37 Poul-Erik Andreasen [this message]
2006-02-21 15:25 ` binding to C: popen jimmaureenrogers
2006-02-21 15:45   ` Poul-Erik Andreasen
2006-02-21 15:52     ` Georg Bauhaus
2006-02-21 16:16       ` Poul-Erik Andreasen
2006-02-21 16:12     ` Alex R. Mosteo
2006-02-21 23:51     ` Jeffrey R. Carter
2006-02-22 13:50 ` Marc A. Criley
2006-02-23  1:10   ` poulerik
replies disabled

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