C question - headers in mmaped files
duncanr at optimation.com.au
Tue Apr 1 21:45:42 EST 2003
dat = (data *) map+64;
dat = ((data*)map) + 64;
i.e. add 64 * sizeof map to machine address.
If you want dat to start 64 bytes in from map, try
dat=(data*)((char*)map+64); /* N.b. avoid confusing whitespace ;) */
Cheers ... Duncan.
On Tue, Apr 01, 2003 at 08:53:17PM +1000, Jepri wrote:
> Hey all, I've got a C question for them who do that sort of thing. Not
> quite linux, but the list is a tad slow thesedays.
> I'm writing some code that writes and reads data out of files using
> mmap, and I get to make up my own file format. It seemed natural to
> have a header describing the file, but I can't figure out how to access
> the header in the mmaped chunk of memory. I thought I could just take
> pointers to anywhere inside the mmaped memory and cast them to whatever
> I wanted, but it doesn't seem to work for me.
> i.e. I tried something really naive like:
> map = (char *) mmap(etc etc)
> head = (header *) map;
> dat = (data *) map+64;
> but data ended up pointing over 1kb heigher than it should have.
> What's the right way to do this? Is there an easy way for me to make
> multiple 'segments' in the file that have different data formats?
More information about the linux