comp.lang.ada
 help / color / mirror / Atom feed
* Writing Data to a file
@ 2011-12-15 18:13 awdorrin
  2011-12-15 18:32 ` Ludovic Brenta
  0 siblings, 1 reply; 5+ messages in thread
From: awdorrin @ 2011-12-15 18:13 UTC (permalink / raw)


I have code that imports the unix 'write' function in order to write a
stream of byte data.

I had thought that replacing this call with the POSIX.IO.Write would
make more sense, so that I was using more of a standard method.

Unfortunately, I cannot access the write function within POSIX.IO, so
I'm stuck with using the Write procedures.

I have the following code, but I'm not sure that I'm doing this the
right way...

declare
  Buf_Last : Stream_Element_Count;
  Buf_Addr : System.Address := AREA_PTR + Storage_Offset(READ_OFFSET);
  Buf : Stream_Element_Array( 1 .. Stream_Element_Count( WRITE_OFFSET
- READ_OFFSET) );
  for Buf'Address use Buf_Addr;
begin
  POSIX.IO.Write( File=>FileHandle, Buffer=>Buf, Last=>Buf_Last);
end;

The original code, using the imported function was:

C_WRITE( File => FileHandle, Buffer=> (Q_AREA_PTR +
Storage_Offset(READ_OFFSET), Num_Bytes=> (WRITE_OFFSET -
READ_OFFSET));

having to use the declare section to overlay the Stream_Element_Array
onto the memory segment of the buffer seems much more complicated; so
I feel like there is likely an easier way to do this, using standard
Ada, and not having to import the C write function.

Anyone have any suggestions?



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

end of thread, other threads:[~2011-12-16 13:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-15 18:13 Writing Data to a file awdorrin
2011-12-15 18:32 ` Ludovic Brenta
2011-12-15 19:23   ` awdorrin
2011-12-16  0:55     ` Randy Brukardt
2011-12-16 13:30     ` Jacob Sparre Andersen

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