+ if (S_ISDIR(statbuf.st_mode)) {
+ DIR *dir;
+ struct dirent *entry;
+
+ dir = opendir(filename);
+ if (!dir) {
+ du_depth--;
+ return 0;
+ }
+
+ len = strlen(filename);
+ if (filename[len - 1] == '/')
+ filename[--len] = '\0';
+
+ while ((entry = readdir(dir))) {
+ char newfile[BUFSIZ + 1];
+ char *name = entry->d_name;
+
+ if ((strcmp(name, "..") == 0)
+ || (strcmp(name, ".") == 0)) {
+ continue;
+ }
+
+ if (len + strlen(name) + 1 > BUFSIZ) {
+ error_msg(name_too_long);
+ du_depth--;
+ return 0;
+ }
+ sprintf(newfile, "%s/%s", filename, name);
+
+ sum += du(newfile);
+ }
+ closedir(dir);
+ print(sum, filename);
+ }
+ else if (statbuf.st_nlink > 1 && !count_hardlinks) {
+ /* Add files with hard links only once */
+ if (is_in_ino_dev_hashtable(&statbuf, NULL)) {
+ sum = 0L;
+ if (du_depth == 1)
+ print(sum, filename);
+ }
+ else {
+ add_to_ino_dev_hashtable(&statbuf, NULL);
+ }
+ }
+ du_depth--;
+ return sum;