file_length() incorrect values

Posted By: Kartoffel

file_length() incorrect values - 04/30/18 16:21

file_length() seems to give incorrect results when it's used for larger files (a couple of megabytes or higher).

Here's a code example of how I used it:
Code:
var fhandle = file_open_read("test.mp3");
var Size = file_length(fhandle);
printf("size: %d", (int)Size);
file_close(fhandle);


What's interesting is that manually retrieving it using the engine's functions seems to give the same faulty results.
Code:
file_seek(fhandle, 0, 2); // seek to end
int Size = (int)file_seek(fhandle, 0, 4); // read position
file_seek(fhandle, 0, 1); // seek back to beginning

Posted By: Superku

Re: file_length() incorrect values - 04/30/18 16:57

Those functions probably return real vars, right (instead of let's say int)? Then you've got your (file) limitations with the var range of around a million (bytes).
You will probably need to use Windows functions instead.
Posted By: Kartoffel

Re: file_length() incorrect values - 04/30/18 17:06

Sounds like this is the case, thanks. Though, I'm confused that they decided to use var for those functions, as it doesn't make sense to get anything else than integers from them.
Posted By: FBL

Re: file_length() incorrect values - 05/14/18 17:31

Yes it is due to var limitations.
My guess is the functions already existed in WDL/C-Script, where there were only var and string.

I fixed this in a dirty way for end of file detection and otherwise avoided usage of file_seek and file_length as much as possible.

#define feof(f) (file_seek(f,1,4) == file_length(f))

if both functions deliver the identical (wrong) value, we've most likely reached end of file grin
Posted By: Kartoffel

Re: file_length() incorrect values - 05/14/18 18:39

I just ended up using the file-functions from stdio laugh
Posted By: FBL

Re: file_length() incorrect values - 05/15/18 14:54

Possibly the better idea.
© 2024 lite-C Forums