Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

get file length

Name: Anonymous 2009-04-17 4:56

Whats the most crossplatform way to get file length in C?

Name: Anonymous 2009-04-17 5:34

I agree with >>2.

FILE *f;
long len;
f = fopen("file", "r");
fseek(f, 0, SEEK_END);
len = ftell(f);
fclose(f);

fstat() is POSIX and is more or less uniform across GNU/Linux, *BSD and Solaris (on Solaris struct elements are in wrong order but have standard names), however I'm not sure how it will behave on real operating systems like Windows 9x, Plan 9 and I-TRON.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List