View Single Post
Old 08-08-2006, 06:37 PM   #7 (permalink)
AssKoala
Anti-Zealot
 
AssKoala's Avatar
 
Join Date: Feb 2006
Location: Atlanta, GA
Posts: 72
AssKoala is on a distinguished road
Send a message via AIM to AssKoala Send a message via MSN to AssKoala Send a message via Yahoo to AssKoala
Quote:
Originally Posted by toe_cutter
ls -lh
Seeing as this is the C++ forum, that's just a stupid comment.

Only a fool would execute a separate application like ls and use a parser to extract the file size data for what can be done in 10 lines of code.

Nevermind that it's OS specific, succeptable to problems if ls's output changes, etc. So,

Quote:
Originally Posted by redhead
Or stat() and then use the provided st_size.
But since this can't be dealth with in a ISO/ANSI way, I guess that was the reason I didn't comment on it in the first place...
That has no relevance to what DJMaze posted or what I responded about.

The purpose of the post was to convert the file size to a human readable number. The structure provided by stat only provides the file size in bytes in the form of the member st_size. It has no bearing whatsoever on the post.

Now, had he said here's an ANSI way to obtain the file size:

Code:
int fileSize(FILE *fp) {
    int size=0,c=getc(fp);
    for (;c!=EOF;c=getc(fp),size++);
    return size;
}
Then responding with functions like stat(), GetFileSize(), GetFileSizeEx(), read_vnode() or whatever other OS specific functions would apply would make sense.
__________________
If you always think like an expert, you'll always be a beginner. | "A handful of knowledgeable people is more effective than an army of fools" -Writing Secure Code, 2nd Ed.
AssKoala is offline   Reply With Quote