comp.lang.ada
 help / color / mirror / Atom feed
* binding to C:  popen
@ 2006-02-21 14:37 Poul-Erik Andreasen
  2006-02-21 15:25 ` jimmaureenrogers
  2006-02-22 13:50 ` Marc A. Criley
  0 siblings, 2 replies; 9+ messages in thread
From: Poul-Erik Andreasen @ 2006-02-21 14:37 UTC (permalink / 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?







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

end of thread, other threads:[~2006-02-23  1:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-02-21 14:37 binding to C: popen Poul-Erik Andreasen
2006-02-21 15:25 ` 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

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