comp.lang.ada
 help / color / mirror / Atom feed
From: awdorrin <awdorrin@gmail.com>
Subject: Writing Data to a file
Date: Thu, 15 Dec 2011 10:13:05 -0800 (PST)
Date: 2011-12-15T10:13:05-08:00	[thread overview]
Message-ID: <344d32d6-a667-407c-bb8e-e0c504e91688@u32g2000yqe.googlegroups.com> (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?



             reply	other threads:[~2011-12-15 18:15 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-15 18:13 awdorrin [this message]
2011-12-15 18:32 ` Writing Data to a file Ludovic Brenta
2011-12-15 19:23   ` awdorrin
2011-12-16  0:55     ` Randy Brukardt
2011-12-16 13:30     ` Jacob Sparre Andersen
replies disabled

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