delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/21/11:42:52

Date: Fri, 21 Mar 1997 11:25:49 -0500 (EST)
From: "art s. kagel IFMX x2697" <kagel AT dg1 DOT bloomberg DOT com>
To: Christopher Keane <keane AT jei DOT umd DOT edu>
Cc: djgpp AT delorie DOT com
Subject: Re: fseek() bug?!?!
In-Reply-To: <5gplk9$fpn@hecate.umd.edu>
Message-Id: <Pine.D-G.3.91.970321112252.28140B-100000@dg1>
Mime-Version: 1.0

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019