#include <errno.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <locale.h>
#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;
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);
}
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);
}
}