From: Francois Fleuret Date: Sat, 5 Mar 2011 21:52:07 +0000 (+0100) Subject: Added a '/' after directory names in the printed results. X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=commitdiff_plain;h=59d5b36b07a5632d24dc99839a96b7371de3d445;p=dus.git Added a '/' after directory names in the printed results. --- diff --git a/dus.c b/dus.c index c698d2e..872f5c1 100644 --- a/dus.c +++ b/dus.c @@ -22,7 +22,7 @@ * */ -#define VERSION_NUMBER "1.2" +#define VERSION_NUMBER "1.3" #define _BSD_SOURCE @@ -94,7 +94,7 @@ int ignore_entry(const char *name) { (ignore_dotfiles && name[0] == '.' && name[1] != '/'); } -size_sum_t entry_size(const char *name) { +size_sum_t entry_size(const char *name, int *isdir) { DIR *dir; struct dirent *dir_e; struct stat dummy; @@ -102,6 +102,7 @@ size_sum_t entry_size(const char *name) { char subname[PATH_MAX]; result = 0; + if(isdir) { *isdir = 0; } if(lstat(name, &dummy) != 0) { if(!(errno == EACCES && ignore_protected_files)) { @@ -119,12 +120,13 @@ size_sum_t entry_size(const char *name) { } 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); + result += entry_size(subname, 0); } } closedir(dir); @@ -187,9 +189,15 @@ struct entry_node { struct entry_node *push_entry(char *name, struct entry_node *head) { struct entry_node *result; + int isdir; result = safe_malloc(sizeof(struct entry_node)); - result->name = strdup(name); - result->size = entry_size(name); + result->size = entry_size(name, &isdir); + if(isdir) { + result->name = safe_malloc(sizeof(char) * strlen(name) + 2); + sprintf(result->name, "%s/", name); + } else { + result->name = strdup(name); + } result->next = head; return result; }