I'd not rely on null-terminated strings... i prefer strings with length.(but it's my personal opinion)
Also i don't like to use any functions i haven't wrote myself,if i can do it without and it also will be faster :-)
on subject, i think it may be better to check for length first,then access the thing (and always do so).
Optimization of showing dir contents function
while(datum = readdir(dr)) if( *datum->d_name != '.' || datum->d_namlen != 2 || datum->d_name[1] != '.') { /* Get file data */ stat(datum->d_name, &buf); printf("%-50s%10d\n", datum->d_name, buf.st_size); }
no need for extra coupling short and sweet and quite understandable.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement