www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/03/19/22:10:35

From: keane AT jei DOT umd DOT edu (Christopher Keane)
Newsgroups: comp.os.msdos.djgpp
Subject: fseek() bug?!?!
Date: 19 Mar 1997 21:25:29 GMT
Organization: University of Maryland, College Park
Lines: 59
Message-ID: <5gplk9$fpn@hecate.umd.edu>
NNTP-Posting-Host: jei.umd.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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