Can anyone make filesize return the size of the file given as its parameter? There seems to be a bug that returns the size of the previous call if the file doesn't exist. Here is some sample code that demonstrates this on my machine (7.5.0).
// Simple ULP to show flaw in filesize function
void displayFileSize(string fileName)
{
string fSize = ""; // Initialize to empty string (size == 1?)
fSize[0] = '\0'; // Strings are zero terminated; erase this way too!
sprintf(fSize, "%d", filesize(fileName));
dlgMessageBox("displayFileSize: " + fileName + "\tSize: " + fSize + ".");
}
void main(void)
{
// Verify that filesize can return '0' when file doesn't exist
// Result: displayFileSize: file.txt Size: 0.
displayFileSize("file.txt");
// Write a string to a file so it exists and has non-zero size
output("file.txt", "wt")
{
printf("Here is some text to write.");
}
// Verify that this new file has a valid size
// Result: displayFileSize: file.txt Size: 27.
displayFileSize("file.txt");
// Demonstrate that a file that doesn't exist 'has the same size' as the last
// file that filesize() processed.
// Result: displayFileSize: f_a_k_e__F_i_l_e.txt Size: 27.
displayFileSize("f_a_k_e__F_i_l_e.txt");
}