2 registered members (AndrewAMD, rki),
391
guests, and 0
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
file_length() incorrect values
#472483
04/30/18 16:21
04/30/18 16:21
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
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:
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.
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
POTATO-MAN saves the day! - Random
|
|
|
Re: file_length() incorrect values
[Re: Superku]
#472485
04/30/18 17:06
04/30/18 17:06
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
OP
Expert
|
OP
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
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.
POTATO-MAN saves the day! - Random
|
|
|
Re: file_length() incorrect values
[Re: Kartoffel]
#472690
05/14/18 17:31
05/14/18 17:31
|
Joined: Sep 2003
Posts: 9,859
FBL
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 9,859
|
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
|
|
|
|