[Gllug] Pointer arithmetic with void *

Tethys tet at accucard.com
Wed Aug 14 17:22:24 UTC 2002


>Just out of interest, I take it this is pretty low level stuff
>you're doing?

Actually, no... I'm writing a umod installer :-) I got fed up with
all the dependencies on obscure Perl libraries for umodpack, so I
thought I'd write one in C.

>Is there a way you could cast the void* that mmap returns directly
>to a struct?

A umod file is basically just an archive of uncompressed files
concatenated together, with a contents table, and a "header"
tacked on the end. Each entry in the contents table has an int
describing the length of the filename, followed by the NUL terminated
filename itself (and then it's offset withing the file, it's length
and some magic flags). The problem is that the int for the filename
length is stored as a variable length numebr itself (from 1 to 5
bytes). Thus it can't be cast to a suitable structure, because the
structure size varies...

    http://wiki.beyondunreal.com/wiki/Package_File_Format/Data_Details

Nice idea if you're constrained for space. However, that's not the case
here. Firstly, the umod contents are stored uncompressed. Secondly, the
whole umod typically only uses less than 10 of these index integers, so
in a file that's serveral hundred KB long, the space benefits over just
using a little endian unsigned 32-bit int (as used elsewhere in the umod)
are negligible, and only really serve to make the file harder to parse...

Tet

-- 
Gllug mailing list  -  Gllug at linux.co.uk
http://list.ftech.net/mailman/listinfo/gllug




More information about the GLLUG mailing list