From: Francois Fleuret Date: Sat, 19 Jun 2010 09:53:32 +0000 (+0200) Subject: Added an S_ISDIR check before opendir() to work on hfsplus volumes (?) X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=afa94ba5350a482648024765bc66abfe8c8c62ef;p=dus.git Added an S_ISDIR check before opendir() to work on hfsplus volumes (?) --- diff --git a/dus.c b/dus.c index 326abeb..03bd980 100644 --- a/dus.c +++ b/dus.c @@ -106,20 +106,22 @@ size_sum_t entry_size(const char *name) { 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;