From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: Concatenating files
Date: Thu, 20 Sep 2007 13:41:31 +0200
Date: 2007-09-20T13:41:31+02:00 [thread overview]
Message-ID: <ygek5qlo978.fsf@hugsarin.dmusyd.edu> (raw)
In-Reply-To: 1190237608.187880.115470@o80g2000hse.googlegroups.com
mhamel_98@yahoo.com writes:
> Hello c.l.a. I have a storage system for a program of mine that
> uses two files for each object - a text header file via text_io and
> a data file via sequential_io. I am wondering if there is an
> elegant way to put the contents of these two files into one. The
> textual header bit is fixed size/length. Any ideas? ObjectAda 95
> on NT.
If ObjectAda 95 on NT has something like POSIX.Memory_Mapping, then
you could do it like this:
Data_Length : constant Natural
:= (File_Size (File) - Fixed_Header_Length) * 8 / Element_Type'Size;
type File_Content is
record
Header : String (1 .. Fixed_Header_Length);
Data : array (1 .. Data_Length) of Element_Type;
end record;
[...]
Address := Map_Memory (Length => File_Size (File),
Protection => Allow_Read + Allow_Write,
Mapping => Map_Shared,
File => File,
Offset => 0);
[...]
Content : File_Content;
for Content'Address use Address;
-- Here you can access Content.Header and Content.Data just like
-- any other object in Ada.
The tricky part in this is when you want to append to the file. For
now I will leave that as an exercise for the reader.
Greetings,
Jacob (a big fan of POSIX.Memory_Mapping ;-)
--
"Banning open source would have immediate, broad, and
strongly negative impacts on the ability of many sensitive
and security-focused DOD groups to protect themselves
against cyberattacks" -- Mitre Corp.
next prev parent reply other threads:[~2007-09-20 11:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-09-19 21:33 Concatenating files mhamel_98
2007-09-20 4:28 ` Jeffrey R. Carter
2007-09-20 11:41 ` Jacob Sparre Andersen [this message]
2007-09-20 13:11 ` gautier_niouzes
2007-09-22 17:38 ` mhamel_98
2007-09-22 20:07 ` Jeffrey R. Carter
2007-09-22 22:51 ` mhamel_98
2007-09-23 1:45 ` Jeffrey R. Carter
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox