*
*/
-#define VERSION_NUMBER "1.2"
+#define VERSION_NUMBER "1.3"
#define _BSD_SOURCE
(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;
char subname[PATH_MAX];
result = 0;
+ if(isdir) { *isdir = 0; }
if(lstat(name, &dummy) != 0) {
if(!(errno == EACCES && ignore_protected_files)) {
}
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);
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;
}