comp.lang.ada
 help / color / mirror / Atom feed
From: emery@linus.mitre.org (David Emery)
Subject: Re: Making EXECL Unix call from Ada
Date: 10 Dec 90 15:51:04 GMT	[thread overview]
Message-ID: <EMERY.90Dec10105104@aries.linus.mitre.org> (raw)
In-Reply-To: cstein@jarthur.claremont.edu's message of 9 Dec 90 19:38:55 GMT

I suspect the problem is that Unix is running off the end of your
string and/or your parameter list.  Try the following:

	with system;
	  -- assumed to provide the object "null_address"
	  -- (also known as "address_zero" or "no_addr" on some compilers)
	with text_io;
	procedure print
	    function execl (name : system.address;
			    arg0 : system.address;
			    arg1 : system.address)	-- all we need
	    return integer;	-- assumed to be the same size as C "int"
	    pragma interface (C, execl);
	    
	    program_name : constant string
			 := "/usr/local/bin/enscript" & Ascii.nul;
	    file_name    : constant string
		         := "/hmc2/guests/lsdada/cliffie/hello" & Ascii.nul;
	    status : integer;
	begin
	    status := execl (name => program_name(program_name'first)'address,
			     arg0 => file_name(file_name'first)'address,
			     arg1 => system.null_address);
	    if status/=0 then
		put_line("True.");
  	    else
		put_line("False");
	    end if;
	end print;

Remember, that in C strings are null-terminated, and represented by
the address of the first element.  Also, from the C definition of the
parameters for execl, the last parameter is of type "address", with
value 0, not the address of an object with value 0.  There's a subtle
difference, in that the former is "0", and the latter is not "0", but
some (non-zero) address.  

Here are the changes to print a user-supplied file.  Append a null to
the end of the user-supplied string, and pass this to C:

	procedure print (file_to_print : string) is
	    ...
	    file_name : constant string
		      := file_to_print & Ascii.nul;
	    ...
	end print;

				dave emery
				emery@aries.mitre.org

<for more tricks like this, see my paper in Tri-Ada on the POSIX Ada
binding prototype.>

      reply	other threads:[~1990-12-10 15:51 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-12-09 19:38 Making EXECL Unix call from Ada Clifford Stein
1990-12-10 15:51 ` David Emery [this message]
replies disabled

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