Re: newbie question [C language]



osmium wrote:
> "Fred_NacH" writes:
>
> > I was wondering, how to retrieve the size/length of a file by only using
> > the ansi functions...
>
> This one often causes a lot of controversy, some people say there is a
> (usually unnamed) system on which it won't work or at least there *could
> have been* a system on which it wouldn't work if such a system had been
> built.
>
> Open the file in *binary* mode, seek to end of file, and use ftell() to see
> where you are. If you like acrimony and pedantry, look around on Usenet for
> these discussions which flare up from time to time.

I expect the problem Randy points out is something like a bug - or at
least lies in the neverland between bug and feature.

fseek to SEEK_END isn't gauranteed to work on a binary file. I think
this is because on some operating systems binary files are made from
fixed size block of some number of bytes. They appear like files in
other systems, but with nulls at the end padding out to the end of the
block.

It's worth pointing out that stat/fstat or a version of it are
available on many platforms even though they aren't standard.

.



Relevant Pages

  • Re: newbie question [C language]
    ... >>> only using the ansi functions... ... >> This one often causes a lot of controversy, ... > or at least lies in the neverland between bug and feature. ... > fseek to SEEK_END isn't gauranteed to work on a binary file. ...
    (comp.programming)
  • Re: linking issue on Redhat 9 with cryptlib 3.1
    ... > Will Google this some more. ... phil@nonospaz:include$ grep __dn_skipname * ... Binary file libnss_hesiod.so matches ... 1st bug in MS win2k source code found after 20 minutes: ...
    (sci.crypt)
  • Store a BMP in a XML Node ?
    ... Is there a way to store and retrieve an image (Or other binary file) as an ... XML node in a file? ... Convert it to text somehow, ...
    (alt.comp.lang.borland-delphi)