Subject: None
To: Benjamin Kenobi <fkrj@crux4.cit.cornell.edu>
From: Jason Thorpe <thorpej@nas.nasa.gov>
List: netbsd-bugs
Date: 05/13/1996 23:25:26
On Mon, 13 May 1996 21:37:35 -0400 (EDT) 
 Benjamin Kenobi <fkrj@crux4.cit.cornell.edu> wrote:

 > 	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. 

Actually, your sample program has a bug.  File sizes are off_t's, which 
are 64-bits under NetBSD.  On a 32-bit system, one has to a little more 
careful.

Your program attempts to print a 64-bit quantity though a 32-bit format.  
This will definitely lose on a big-endian system (you're running an 
amiga, right?)

 > 
 > #include <stdio.h>
 > #include <sys/types.h>
 > #include <sys/stat.h>
 > 
 > void main( void )
 > {
 > 
 > 	char file_name[100];
 > 	FILE *f;
 > 	struct stat st;
 > 	int rv, fd;	
 > 
 > 	printf("Enter filename to stat : ");
 > 	scanf("%s", &file_name);
 > 
 > 	f = fopen(file_name, "r"); 
 > 
 > 	if ( !f )
 > 	{
 > 		printf("fopen() failed\n");
 > 		exit(0);
 > 	}
 > 
 > 	fd = fileno(f);
 > 	printf("fileno() returned %d\n", fd);
 > 
 > 	rv = fstat(fd, &st);
 > 	printf("fstat() returned %d\n", rv);
 > 
 > 	printf("st.st_size = %d\n", st.st_size);
 > 
 > 	fclose(f);
 > }
 > 
 > >Fix:
 > 
 > 	No clue.
 > 
 > 

----save the ancient forests - http://www.bayarea.net/~thorpej/forest/----
Jason R. Thorpe                                       thorpej@nas.nasa.gov
NASA Ames Research Center                               Home: 408.866.1912
NAS: M/S 258-6                                          Work: 415.604.0935
Moffett Field, CA 94035                                Pager: 415.428.6939