- 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)) {
+ if(isdir) { *isdir = 1; }
+ 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, 0);
+ }
+ }
+ closedir(dir);
+ } else {
+ if(!(errno == EACCES && ignore_protected_files)) {
+ fprintf(stderr,
+ "dus: Can not open directory %s: %s\n",
+ name, strerror(errno));
+ exit(EXIT_FAILURE);