TAP_Hdd_Flen

Topfield Documentation

dword TAP_Hdd_Flen(TYPE_File *fp);

It returns the number of bytes in the opened file specified by fp.

Additional Documentation

There seems to be a bug with various HDD file handling code, particularly the TAP_Hdd_Flen() where it will report the length incorrectly if the length is a multiple of 512bytes. This one stung me ages ago (when wondering why some code I wrote wasn't always processing the last bit of particular file).

The work around is simple-

example:

TYPE_File* fp;
int filelength;
if (( fp = TAP_Hdd_Fopen( LOG_FILE) ))
{
   filelength=TAP_Hdd_Flen( fp );
   if (filelength!=0 && (filelength%512)==0) filelength+=512;  //TOPFIELD BUG WORKAROUND.
snip etc
}

libutils? contains a fixit module. Simply include tapapifix.h and calls to TAP_Hdd_Flen will be replaced with a version that includes the above code.

MikB: As an additional problem, it seems that TAP_Hdd_Flen() is not universally broken. It does in fact return the correct length (even with 512 byte multiples), on the condition that the file was written by the Toppy to its own disk (e.g. created by a TAP). I have been successfully writing files that are forced to be 512 byte multiples, and reading them back correctly without ever being aware of this bug. It only seems to affect files that were imported from the PC, e.g. by Altair. It is these files that are reported short by 512 bytes, if they are a non-zero multiple of 512 bytes.