Subject: Re: Strange open & f/stat behavior in 1.6Q
To: Steve Foster <steve@devidian.me.uk>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: port-sparc
Date: 04/17/2003 04:46:20
> The following test code should return the size of /etc/hosts:

Not quite.

> 	printf("Size: %d\n", sbuf.st_size);

Try compiling with -Wformat.

You're getting zero because the way 64-bit ints are passed on the sparc
means that printf is using the high half of the size.  (It "works" on
your i386 box because its passing convention ends up making printf use
the low half of the size.)

It'll do what you expect if you make it (int)sbuf.st_size - or if you
make it %lld and (long long int)sbuf.st_size.  (On the sparc you don't
need the cast even to keep -Wformat happy, but it's needed to be
type-correct, and on an ILP64 machine like sparc64 or alpha, where
st_size may be int or long int instead of long long int, -Wformat may
want it.)

If you were to use it with a file >2G in size, of course, using int
won't DTRT on the sparc.  But that seems unlikely for /etc/hosts.

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B