From: Hans-Bernhard Broeker Newsgroups: comp.os.msdos.djgpp Subject: Re: filelength(): POSIX or not Date: 31 Oct 2000 18:53:10 GMT Organization: Aachen University of Technology (RWTH) Lines: 22 Distribution: world Message-ID: <8tn4em$m65$1@nets3.rz.RWTH-Aachen.DE> References: <972911905 DOT 508266 AT shelley DOT paradise DOT net DOT nz> <753uvso5d74rfdhndnrc98aoksgl0i7hvp AT 4ax DOT com> NNTP-Posting-Host: acp3bf.physik.rwth-aachen.de X-Trace: nets3.rz.RWTH-Aachen.DE 973018390 22725 137.226.32.75 (31 Oct 2000 18:53:10 GMT) X-Complaints-To: abuse AT rwth-aachen DOT de NNTP-Posting-Date: 31 Oct 2000 18:53:10 GMT Originator: broeker@ To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Damian Yerrick wrote: > fopen() the file in "rb" mode, fseek() to the end, and read the > length with ftell(). This is ANSI so it should work on any full > ANSI C compiler. The calling sequence is ANSI, right. But it's not at all ANSI to assume it will always do what you think it does. To quote the C standard on this: [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. 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. -- Hans-Bernhard Broeker (broeker AT physik DOT rwth-aachen DOT de) Even if all the snow were burnt, ashes would remain.