[Proj] NAD problems on OSX 10.5 Leopard

William Kyngesburye woklist at kyngchaos.com
Wed Jan 16 10:08:46 EST 2008


On Jan 15, 2008, at 11:30 PM, William Kyngesburye wrote:

> On Jan 15, 2008, at 10:42 PM, Frank Warmerdam wrote:
>
>> In the meantime, I imagine it would not be too hard to alter the  
>> nadcon
>> reading and writing functions to use some sort of consistent binary
>> file.  But I'm even to lazy to attempt that just now.
>
> Ah, the extra bytes are pointer for the *cvs part of the CTABLE  
> structure?
>
>  fwrite(ct.cvs, tsize, 1, stdout)
>
I guess not, since...
>
> Or is it written as part of the &ct fwrite?
>
>  fwrite(&ct, sizeof(ct), 1, stdout)
>
> How about:
>
>  fwrite(ct.id, sizeof(ct.id), 1, stdout)
>  fwrite(ct.ll, sizeof(ct.ll), 1, stdout)
>  fwrite(ct.del, sizeof(ct.del), 1, stdout)
>  fwrite(ct.lim, sizeof(ct.lim), 1, stdout)
>
> This way it skips the pointer part of ct.cvs.
>
This works:

if (fwrite(&ct.id, sizeof(ct.id), 1, stdout) != 1 ||
	fwrite(&ct.ll, sizeof(ct.ll), 1, stdout) != 1 ||
	fwrite(&ct.del, sizeof(ct.del), 1, stdout) != 1 ||
	fwrite(&ct.lim, sizeof(ct.lim), 1, stdout) != 1 ||
	fwrite(ct.cvs, tsize, 1, stdout) != 1) {
	fprintf(stderr, "output failure\n");
	exit(2);
}

This creates a file consistent enough at least for different  
architectures on OSX.  Combined with my endian patches, which forces  
the files to be little-endian on both PPC and Intel, the NAD files are  
usable on PPC + Intel, 32bit + 64bit.

> On the other side, though, with the current extra bytes, the fseek()  
> in nad_ctable_load() doesn't seem to be skipping over those bytes,  
> so they are read as part of the data.  Could it be due to sizeof(ct)  
> used in nad2bin, but sizeof(struct CTABLE) used in  
> nad_ctable_load()?  Or an fseek bug?
>

So, is sizeof(struct CTABLE) supposed to be the size including the  
*cvs pointer?  If so, then it's a bug (OSX at least) in sizeof.  But  
the pj_malloc(sizeof(struct CTABLE)) in nad_ctable_init() seems to be  
working properly.

To make sure, how about:

sizeof(&cd.id) + sizeof(&cd.ll) + sizeof(&cd.del) + sizeof(&cd.lim)

>

-----
William Kyngesburye <kyngchaos*at*kyngchaos*dot*com>
http://www.kyngchaos.com/

"Those people who most want to rule people are, ipso-facto, those  
least suited to do it."

- A rule of the universe, from the HitchHiker's Guide to the Galaxy




More information about the Proj mailing list