X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=dus.c;h=a4b5d0acc1906b243786ee42c16604e3b535a596;hb=4b8de32c8576d189eeef5ab22ee70f380d001613;hp=5b19766514119eee7d28680e7ceae0c8f042eb4e;hpb=acb173574185b068ee9c46d244900c81fa31a947;p=dus.git diff --git a/dus.c b/dus.c index 5b19766..a4b5d0a 100644 --- a/dus.c +++ b/dus.c @@ -33,12 +33,24 @@ #include #include #include +#include -#define BUFFER_SIZE 1024 +#define BUFFER_SIZE 4096 typedef int64_t size_sum_t; -size_sum_t file_or_dir_size(char *name) { +int ignore_dotfiles = 1; + +/********************************************************************/ + +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; @@ -60,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); } @@ -121,7 +132,6 @@ int compare_files(const void *x1, const void *x2) { } } - void print_sorted(struct file_with_size *root, int height) { struct file_with_size *node; struct file_with_size **nodes; @@ -184,6 +194,8 @@ int main(int argc, char **argv) { root = 0; + setlocale (LC_ALL, ""); + if(argc > 1) { for(k = 1; k < argc; k++) { root = create(argv[k], root); @@ -194,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); } }