Re: Application Reading Itself



"ReaperUnreal" <reaperunreal@xxxxxxxxx> writes:
Actually, I found the problem myself, and you were all way off. You'll
carefully notice that I fseek to the end of the file with a -8 offset.
Apparently, the offset is ignored if I use the SEEK_END flag. So an
additional fseek solved the problem.

Please provide some context when you post a followup.

According to the C standard:

For a binary stream, the new position, measured in characters from
the beginning of the file, is obtained by adding offset to the
position specified by whence. The specified position is the
beginning of the file if whence is SEEK_SET, the current value of
the file position indicator if SEEK_CUR, or end-of-file if
SEEK_END. A binary stream need not meaningfully support fseek
calls with a whence value of SEEK_END.

The last sentence is intended to cover systems that don't store the
exact size in bytes of a binary file; for example, a binary file can
legally be implicitly padded with null bytes up to a multiple of some
block size. As far as I know, it's unlikely that any system you're
likely to be using is affected by this.

In other words, I'd be very surprised if fseek() with the SEEK_END
flag actually did ignore the offset (though it's allowed by the
standard). Though you may be correct, my guess is that you've somehow
misunderstood what's really going on, and your fix works only by
accident.

--
Keith Thompson (The_Other_Keith) kst-u@xxxxxxx <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
.



Relevant Pages

  • Re: fseek
    ... > If offset is a value returned by ftell (which returns the current file ... > position), and origin is SEEK_SET, then fseek() sets the position to the ... > can't text streams be fseek'ed randomly like a binary stream can ... After all, if I fgetc 9 times, the 10th will produce a specific ...
    (comp.lang.c)
  • Re: Application Reading Itself
    ... carefully notice that I fseek to the end of the file with a -8 offset. ... the offset is ignored if I use the SEEK_END flag. ...
    (comp.lang.c)
  • Re: Application Reading Itself
    ... carefully notice that I fseek to the end of the file with a -8 offset. ... the offset is ignored if I use the SEEK_END flag. ...
    (comp.lang.c)
  • Re: feof(), fseek(), fread()
    ... offset of a file and still be able to detect EOF?i.e. ... this without fseek(), that's why I posted this question. ... EOF is a macro defined in stdio.h probably as.. ... eoff = ftell; ...
    (comp.lang.c)
  • Re: feof(), fseek(), fread()
    ... offset of a file and still be able to detect EOF?i.e. ... I still don't know how can I detect EOF while I'm always use fseek() ... The end-of-file indicator indicates that the last attempt to read from ...
    (comp.lang.c)