Gamestudio Links
Zorro Links
Newest Posts
Performance reporting showing Annual and monthly % returns
by OptimusPrime
Today at 01:19
Issue with inconsistent test results
by kvm
Yesterday at 17:24
Access string content through another string
by ChrstphFr
Yesterday at 11:30
How to return a vector from a function
by Superku
Yesterday at 05:39
Vector Displacement, realtime Blendshapes
by jumpman
08/14/18 23:46
Code Repository
by OptimusPrime
08/14/18 13:25
Votes for future features
by OptimusPrime
08/14/18 07:18
AUM Magazine
Latest Screens
AckCon'18 - Lotter vs the World 2 - Preview Release
Evonet Beta v1.0 : Online Project Development Template
Lake scene
Forgotten Tales - Demo version
Who's Online
6 registered (Dalla, kvm, jenGs, firecrest, alibaba, bailemad), 452 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Ulenspegel, toto, FloMi, behr065, OptimusPrime
18027 Registered Users
Topic Options
Rate This Topic
#472483 - 04/30/18 18:21 file_length() incorrect values
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2210
Loc: 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:
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

_________________________
POTATO-MAN saves the day! - Random

Top
#472484 - 04/30/18 18:57 Re: file_length() incorrect values [Re: Kartoffel]
Superku Offline
Senior Expert

Registered: 09/13/03
Posts: 6746
Loc: Kiel (Germany)
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.
_________________________
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Superku The Game

Severely outdated footage: http://store.steampowered.com/app/407570

Top
#472485 - 04/30/18 19:06 Re: file_length() incorrect values [Re: Superku]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2210
Loc: 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

Top
#472690 - 05/14/18 19:31 Re: file_length() incorrect values [Re: Kartoffel]
Firoball Offline
Senior Expert

Registered: 09/10/03
Posts: 9831
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

Top
#472692 - 05/14/18 20:39 Re: file_length() incorrect values [Re: Firoball]
Kartoffel Offline
Expert

Registered: 06/11/09
Posts: 2210
Loc: Bavaria, Germany
I just ended up using the file-functions from stdio laugh
_________________________
POTATO-MAN saves the day! - Random

Top
#472712 - 05/15/18 16:54 Re: file_length() incorrect values [Re: Kartoffel]
Firoball Offline
Senior Expert

Registered: 09/10/03
Posts: 9831
Possibly the better idea.

Top


Moderator:  jcl, Nems, Spirit, Tobias 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de