- if (cp + NLENGTH(dp) + 2 >= name + BUFSIZ)
- continue;
- strcpy (cp, dp->d_name);
- if (stat (name, &st) != -1 && S_ISDIR(st.st_mode)) {
- /*
- * Check if this was really a symbolic link pointing at
- * a directory. If not, then decrement link count.
- */
- if (lstat (name, &st) == -1)
- nlink--;
- addfold (base);
+ child = concat (prefix, dp->d_name, (void *)NULL);
+ if (stat (child, &st) != -1 && S_ISDIR(st.st_mode)) {
+ /* addfold saves child in the list, don't free it */
+ addfold (child);
+ } else {
+ free (child);