Date: Wed, 1 Nov 2000 10:23:24 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: djgpp AT delorie DOT com Subject: Re: filelength(): POSIX or not In-Reply-To: <8tn4em$m65$1@nets3.rz.RWTH-Aachen.DE> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On 31 Oct 2000, Hans-Bernhard Broeker wrote: > [ISO-C 89:7.9.9.2#2, C99 draft 7.19.9.2#2]: > > A binary stream > need not meaningfully support fseek calls with a whence > value of SEEK_END. To put this in a practical perspective, this does work in DJGPP. > It's long-standing knowledge in the C newsgroups there is, in fact, no > way at all to portably find the length of a given file other than > reading all of it and adding the byte counts. By ``portable'' you probably mean ANSI-portable. Because Posix does have a portable way: stat/fstat. Anyway, the validity of the above assertion depends on the definition of ``length of a file''. On systems where fseek doesn't work well with SEEK_END, this definition (or, more accurately, the intended use of file's length in the program) is very important. For some definitions, even reading the file and counting bytes won't yield a meaningful result.