I have a file that gets updated from time to time and some of the data inside the file changes length.
This requires rippling the data after the insertion up or down depending on the length of the new data.
[---data---|old value|---data---]EOF - original file (with old value in the middle)
- new value arrives...
[updated value] - to be inserted into the original file
[---data---|updated value|---data---]EOF - new file (with the longer updated value)
So all that is working OK, all ways; shorter to longer, longer to shorter and same length to same length.
The problem is that when it goes longer to shorter the file size shrinks but it still keeps the original length.
It will recognise the extra data when lengthened but not when shortened.
Subsequently the file size blows out in length over time. I need to be able to place a NEW end of file marker at the end, or rewrite the file size parameter. I have tried inserting EOF (-1 of 0xff) but this goes unnoticed.
The only way I can get it to change size to match the data content is to:
- Read the original file into a new empty file (copy)
- Delete the original file
- Make all my changes to the file copy
- Save this new file as the original file name
This could be abbreviated if there was a 'rename' function but alas, no.
So question time.... HOW do I set an end of file marker (EOF) into the file data???