Help With Getting A File Size.


GP2X_Coder

Member
Joined
May 17, 2006
Messages
220
Age
51
Location
USA
Website
mysite.verizon.net
I am trying to convert all of my direct x code over to my new gp2x so I can start releasing games but i ran into a little problem. On windows when I wanted to check and see if a file existed and get the size of the file I could call getfilesize and pass a windos handle to the function and it would return the value of the file in bytes if it was there 0 if there were no such file. Is there anything like this that will work on Linux?


Thanks alot.

(I basically need this to check and see if a person creates a save game file or not so my program will know to load it in or just load the defaults.)

Any help would be appreciated.
 
The only 'C' standard way is to do this..

o fseek() to end of the file
o ftell() to obtain current index of file pointer

The Unix way of doing it is to use the stat/fstat type calls on the filename, where you can get the file size and all sorts of goodies about it. But for maximuim portability between OSes, just use the C way.

jeff
 
The only 'C' standard way is to do this..

o fseek() to end of the file
o ftell() to obtain current index of file pointer

The Unix way of doing it is to use the stat/fstat type calls on the filename, where you can get the file size and all sorts of goodies about it. But for maximuim portability between OSes, just use the C way.

jeff
This is okay if the file is already open but that is not possible if it
does not exist.

The ANSI C function: fp = fopen("filename", "r") will fail if the file
does not exist and set fp == NULL.

Use this to test for file existence AND accessability. Need to watch
out for ownership issues.

If the open() succeeds then you might need to use freopen() to
change to read-write access. Again, watch out for ownership issues.
 
Last edited by a moderator:
GP2X is Linux, so the Posix way should work:

stat( fullpath , &info );
filesize = info.st_size;
 
Thanks again for all your help I will apply some of these methods and see which one works best for me. Its great to have such a cool community that helps each other out.
 
Back
Top