Mail Archives: djgpp/1997/03/21/11:42:52
Fseek() allows you to seek past the end of file and if you write to the
new location the file will be expanded to the new size either by filling
the intervening space with nulls or by allocating a sparse file as the OS
permits. Obviously DOS does not support sparse files so the file is
allocated any additional disk space, null or garbage filling (I'm not
sure, but it is easy enough to check) to the new size as soon as you
write to the new location if you do.
Art S. Kagel, kagel AT ts1 DOT bloomberg DOT com
On 19 Mar 1997, Christopher Keane wrote:
>
> Hi all,
>
>
> I've run into a strange problem which appears to be in fseek().
>
> I have some code which has worked fine both under BC and Watcom 9.5, but
> doesn't in DJGPP 2.01. Perhaps someone can tell me if I am making a bad
> assumption...
>
> The code:
>
> FILE *fin;
>
> ...
>
> while( ! feof(fin) )
> {
>
> ...
>
> if( ... )
> {
> fread(.....)
> ...
> }
> else
> {
> fseek(....)
> }
>
> }
>
> Obviously if the file fseeks past EOF, the program should dump out of the
> while. It does this correctly when the fread hits the EOF.... However,
> it goes on for ever if it fseeks past the EOF.
>
> So, I checked feof(fin) before and after the fseek.... On EOF, feof()
> before the fseek returns 64, so I know its past the end of the file.
> However, when I do a feof(fin) after the fseek() knowing full well that it
> is EOF, it returns 0!
>
> It appears that fseek resets the error condition on EOF, causing this
> loop to fail. I solved this with checking the feof() before the fseek()
> and breaking, but I don't understand why this should fail.
>
> Anyone?
>
>
>
>
>
> --
> Cheers,
> ------------------------------------------------------------------------------
> Christopher M. Keane keane AT jei DOT umd DOT edu
> Joint Education Initiative keane AT glue DOT umd DOT edu
> Department of Geology
> University of Maryland at College Park
>
- Raw text -