EOF End of File

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys, I have a simple routine that I can't get working.  I'm using ff_seek to find the end of file but it hangs, i.e. does not detected the EOF.  Have a look below:

int ff_fseek(struct ff_file * pxStream, int iOffset, int iWhence ){

	char * ptr = pxStream->free_data;

	if(iWhence == FF_SEEK_SET){
		pxStream->ptr_to_data = pxStream->free_data;

		if(iOffset > 0){
			ptr += iOffset;
			pxStream->ptr_to_data = ptr;
		}
	}
	else if(iWhence == FF_SEEK_END){
		while(*ptr != EOF){
			ptr++;
		}
		if(iOffset < 0){
			ptr += iOffset;
		}
		pxStream->ptr_to_data = ptr;
	}
	else if(iWhence == FF_SEEK_CUR){
		ptr += iOffset;
		pxStream->ptr_to_data = ptr;
	}
	return 0;
}

And the call I'm making is thus:

	ff_fseek(Xstream, EOF, FF_SEEK_END);
	ff_fputc(Xstream, 't');
	ff_fputc(Xstream, 'e');
	ff_fputc(Xstream, 's');
	ff_fputc(Xstream, 't');
	ff_fputc(Xstream, EOF);

Any help or input is much appreciated guys.

 

 

This topic has a solution.
Last Edited: Fri. Apr 26, 2019 - 03:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Fianawarrior wrote:

char * ptr = pxStream->free_data;

while(*ptr != EOF){
	ptr++;
}

 

Isn't EOF a value not representable by a char?

 

I recall it is an integer with value -1 (all 1 bits).

Since *ptr is a char, it can never be equal to

this value and you will get an infinite loop.

 

--Mike

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I checked a text document in the filing system and it does not even use the EOF.  It seems that it used the size of file instead to mark the end of the file.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

0x1A EOF markers is something from the days of CP/M. I think it's a long time since anyone has ever really used that as a way of determining where a file ends (usually because the data itself may contain 0x1A - back in the day that caused all kinds of problems when you copied files and they were truncated at the first 0x1A - in fact that's why copy has the "/b" option). As you have discovered you know the extent of the data because of the sz field in the directory entry. (which is why it's vital this must be maintained accurately).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The EOF I was referring to is different from the

ASCII character.  See cplusplus.com EOF

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

He's doing an ff_putc(). Sure looks like ASCII EOF to me. (and yes I know about the EOF condition on an fgetc, which is different: usually (int) -1 rather than 0x1A)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Oops, I kinda misread the whole thing!!

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If it is an ASCII file, then ASCII EOF is probably OK. But, for a generic data file, then its not so good.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If this is C code, and I saw EOF in the code, like avr-mike I would certainly expect it to be the EOF as defined in stdio.h ie. (-1).

If someone is reusing the identifier EOF and defining it to some other value I would say that's a very bad idea.

Or am I missing something here?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Guys, I was barking up the wrong tree, I have to implement the EOF, the fat32 filing systems uses a file size variable, i.e. it does not pend a EOF in the fat32 file entry do donate the end of file.

 

oops!

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

nice the way you can back track with long file name and rebuild the msdos name.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

oh, when writing the EOF is this when I should save the cluster data and update the file size?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Get EOF out of your mind. There is no such concept. Binary and text files end when you get to the size in the directory entry.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

your correct clawson.