return 0;
}
- dir = opendir(name);
-
- if(dir) {
- while((dir_e = readdir(dir))) {
- if(!ignore_entry(dir_e->d_name)) {
- snprintf(subname, PATH_MAX, "%s/%s", name, dir_e->d_name);
- result += entry_size(subname);
+ if(S_ISDIR(dummy.st_mode)) {
+ dir = opendir(name);
+ if(dir) {
+ while((dir_e = readdir(dir))) {
+ if(!ignore_entry(dir_e->d_name)) {
+ snprintf(subname, PATH_MAX, "%s/%s", name, dir_e->d_name);
+ result += entry_size(subname);
+ }
}
+ closedir(dir);
+ } else {
+ fprintf(stderr, "Can not open directory %s: %s\n", name, strerror(errno));
+ exit(EXIT_FAILURE);
}
- closedir(dir);
- } else {
- if(S_ISREG(dummy.st_mode)) {
- result += dummy.st_size;
- }
+ } else if(S_ISREG(dummy.st_mode)) {
+ result += dummy.st_size;
}
return result;