Gamestudio Links
Zorro Links
Newest Posts
What are you working on?
by Emre
Today at 01:03
New Zorro version 1.83
by claudio
Yesterday at 17:22
Ahead bias when retrain
by jcl
Yesterday at 12:27
Huge array for Deep Learning
by jcl
Yesterday at 12:06
[LBGUI] Memory not released!
by EVO
05/23/18 22:39
http_post undeclared identifier
by Superku
05/23/18 22:10
Pan/Tilt in relation to entity?
by Superku
05/23/18 20:59
AUM Magazine
Latest Screens
Lake scene
Forgotten Tales - Demo version
RPG PARTY
Triton Wing now available on Steam
Who's Online
9 registered (Slin, Quad, Superku, AndrewAMD, 3run, jyd, mk_1, 2 invisible), 464 Guests and 3 Spiders online.
Key: Admin, Global Mod, Mod
Newest Members
Rayharry, AgentShark, rpauletto, tuuPaul, LaserJock2000
17960 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: 2203
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 Online
Senior Expert

Registered: 09/13/03
Posts: 6692
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: 2203
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: 9810
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: 2203
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: 9810
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