| 3676 | This is desirable when processing directories recursively. */ |
| 3677 | |
| 3678 | static void |
| 3679 | extract_dirs_from_files (char const *dirname, bool command_line_arg) |
| 3680 | { |
| 3681 | idx_t i, j; |
| 3682 | bool ignore_dot_and_dot_dot = (dirname != NULL); |
| 3683 | |
| 3684 | if (dirname && LOOP_DETECT) |
| 3685 | { |
| 3686 | /* Insert a marker entry first. When we dequeue this marker entry, |
| 3687 | we'll know that DIRNAME has been processed and may be removed |
| 3688 | from the set of active directories. */ |
| 3689 | queue_directory (NULL, dirname, false); |
| 3690 | } |
| 3691 | |
| 3692 | /* Queue the directories last one first, because queueing reverses the |
| 3693 | order. */ |
| 3694 | for (i = cwd_n_used; 0 < i; ) |
| 3695 | { |
| 3696 | i--; |
| 3697 | struct fileinfo *f = sorted_file[i]; |
| 3698 | |
| 3699 | if (is_directory (f) |
| 3700 | && (! ignore_dot_and_dot_dot |
| 3701 | || ! basename_is_dot_or_dotdot (f->name))) |
| 3702 | { |
| 3703 | if (!dirname || f->name[0] == '/') |
| 3704 | queue_directory (f->name, f->linkname, command_line_arg); |
| 3705 | else |
| 3706 | { |
| 3707 | char *name = file_name_concat (dirname, f->name, NULL); |
| 3708 | queue_directory (name, f->linkname, command_line_arg); |
| 3709 | free (name); |
| 3710 | } |
| 3711 | if (f->filetype == arg_directory) |
| 3712 | free_ent (f); |
| 3713 | } |
| 3714 | } |
| 3715 | |
| 3716 | /* Now delete the directories from the table, compacting all the remaining |
| 3717 | entries. */ |
| 3718 | |
| 3719 | for (i = 0, j = 0; i < cwd_n_used; i++) |
| 3720 | { |
| 3721 | struct fileinfo *f = sorted_file[i]; |
| 3722 | sorted_file[j] = f; |
| 3723 | j += (f->filetype != arg_directory); |
| 3724 | } |
| 3725 | cwd_n_used = j; |
| 3726 | } |
| 3727 | |
| 3728 | /* Use strcoll to compare strings in this locale. If an error occurs, |
| 3729 | report an error and longjmp to failed_strcoll. */ |
no test coverage detected