From: Francois Fleuret Date: Fri, 26 Feb 2010 09:57:00 +0000 (+0100) Subject: Added an option ignore_dotfiles. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=4b8de32c8576d189eeef5ab22ee70f380d001613;p=dus.git Added an option ignore_dotfiles. --- diff --git a/dus.c b/dus.c index 338b69b..a4b5d0a 100644 --- a/dus.c +++ b/dus.c @@ -33,14 +33,24 @@ #include #include #include +#include #define BUFFER_SIZE 4096 typedef int64_t size_sum_t; +int ignore_dotfiles = 1; + /********************************************************************/ -size_sum_t file_or_dir_size(char *name) { +int ignore_entry(const char *name) { + return + strcmp(name, ".") == 0 || + strcmp(name, "..") == 0 || + (ignore_dotfiles && name[0] == '.'); +} + +size_sum_t file_or_dir_size(const char *name) { DIR *dir; struct dirent *dir_e; struct stat dummy; @@ -62,8 +72,7 @@ size_sum_t file_or_dir_size(char *name) { if(dir) { while((dir_e = readdir(dir))) { - if(strcmp(dir_e->d_name, ".") && - strcmp(dir_e->d_name, "..")) { + if(!ignore_entry(dir_e->d_name)) { snprintf(subname, BUFFER_SIZE, "%s/%s", name, dir_e->d_name); result += file_or_dir_size(subname); } @@ -197,8 +206,7 @@ int main(int argc, char **argv) { dir = opendir("."); if(dir) { while((dir_e = readdir(dir))) { - if(strcmp(dir_e->d_name, ".") && - strcmp(dir_e->d_name, "..")) { + if(!ignore_entry(dir_e->d_name)) { root = create(dir_e->d_name, root); } }