Subject: Re: port-amiga/2406: port-amiga
To: None <netbsd-bugs@NetBSD.ORG>
From: der Mouse <mouse@Collatz.McRCIM.McGill.EDU>
List: netbsd-bugs
Date: 05/14/1996 05:41:19
> >Synopsis:       fstat() returns 0 for st_size (file lengths)

> 	fstat() and stat() return 0 for the file length in the stat
> 	structure.  It may be that they return other incorrect values
> 	as well.  Please let me know what you find.

> /* Compile and run this program.  It always seems to return 0 for the
>  * file size.  [...]

I find your program to be buggy.

> void main( void )

This is incorrect, but that's not what's wrong.

> 	printf("st.st_size = %d\n", st.st_size);

Here's the problem.  st.st_size is not an int, does not promote to an
int, and thus cannot be printed with %d; you are getting garbage
because of this mismatch.  The garbage just happens to be 0 on your
particular test case.  (It's not quite entirely meaningless; on an
Amiga I believe it will be the high 32 bits of the real size.)

Try

	printf("st.st_size = %d\n", (int)st.st_size);

(which will break when the file size overflows an int; I suppose you
could use %ld and long, which won't make any difference on most
machines).  Or use the "correct" format:

	printf("st.st_size = %qd\n", st.st_size);

(I put "correct" in quotes because there is no Standard C format that
works for NetBSD's st.st_size.  I understand the next C standard is
expected to address this issue.)

					der Mouse

			    mouse@collatz.mcrcim.mcgill.edu