Subj : Re: newbie question [C language] To : comp.programming From : Alan Balmer Date : Tue Jul 05 2005 01:10 pm On 1 Jul 2005 19:34:32 -0700, websnarf@gmail.com wrote: >Fred_NacH wrote: >> I was wondering, how to retrieve the size/length of a file by only using >> the ansi functions... > >The C language has a problem where the size of file that can be defined >by the platform can exceed the largest integer size that the language >itself supports. This is clearly a serious issue for 32-bit OSes that >support 64 bit files. So using functions like ftell() or even >(f)stat() is not really guaranteed to work. And fstat() is not a standard function anyway. > In fact I have no idea >what a programmer should expect ftell() to ever tell them. For binary streams, it gives you the position in bytes from the beginning of the file. For text streams, it's useful for remembering a file position to be later used by fseek(), but has no defined interpretation. > On Windows >systems, int is usually defined as 32-bits, and ftell() returns an int, >however clearly the OS supports 64-bit files. The standard specifies that ftell returns long int. > >Your system may support a function like _fstati64(), or some other >similar function which is more likely to give you want you are looking >for. On a couple Windows compilers I use, _fstati64() outputs to a >structure which is syntactically equivalent to the posix structure >struct stat, though it may contain additional reserved entries and will >define st_size as __int64. Of course the size of a "directory" or >abstract file (such as "con") does really make any sense, but you can >use the st_mode entry to figure out whether or not you have accessed an >ordinary file or not. -- Al Balmer Balmer Consulting removebalmerconsultingthis@att.net .