Angel
4/29/2011 1:47:00 PM
On 2011-04-29, Malcolm McLean <malcolm.mclean5@btinternet.com> wrote:
> On Apr 29, 12:38?am, Angel <angel+n...@spamcop.net> wrote:
>> Hi folks,
>>
>>
>> Currently I read the file with the fread() call and structures declared
>> like this:
>>
>> struct item_v1_header
>> {
>> ? char ? ? ? ? ?signature[4];
>> ? char ? ? ? ? ?version[4];
>> ? uint32_t ? ? ?generic_name_strref;
>> ? <...>
>>
>> } __attribute__((__packed__));
>>
>> [ to fread() ]
>>
> No this is a bad habit.
Well, actually I started this just as an excuse to meddle with the
fread() function. Since the file consists of a header followed by one or
more data blocks all with the same layout, it seemed the most logical
choice. And I was actually considering perhaps using mmap() instead of
fread().
> Write functions to read a 16 and 32-bit big and little endian integer
> from file, then use them to read each member separately.
Each structure has quite a few such members, resulting in a huge number
of separate reads. Though I agree that is the most portable way to do
it. But also the most boring, and I am doing this mainly for fun. (And
to learn something, hence my post here.)
> The software might just run on Intel now, but you wnat to be able to
> move routines as easily as possible to new platforms. Why create a
> platform dependency?
The software that uses these files is over 10 years old and proprietary,
I don't think it'll be ported to any other platform anytime soon. :-)
(Yes, there is a Linux implementation in GemRB, but as far as I know
that one only works on Intel as well.)
So platform independence was not the first thing on my mind when I
started on this, but with the great hints I've been given here it is
something I will attempt to achieve.
--
The perfected state of a spam server is a smoking crater.
- The Crater Corollary to Rule #4