/*
- * dus is a simple utility designed to display the list of files and
- * directories with disk occupancy, sorted according to it.
+ * dus is a simple utility to display the files and directories
+ * according to their total disk occupancy.
*
- * Copyright (c) 2009 Francois Fleuret
+ * Copyright (c) 2010 Francois Fleuret
* Written by Francois Fleuret <francois@fleuret.org>
*
* This file is part of dus.
#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <locale.h>
-#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;
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);
}
}
}
-
void print_sorted(struct file_with_size *root, int height) {
struct file_with_size *node;
struct file_with_size **nodes;
root = 0;
+ setlocale (LC_ALL, "");
+
if(argc > 1) {
for(k = 1; k < argc; k++) {
root = create(argv[k], root);
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);
}
}