| 4019 | /* Sort the files now in the table. */ |
| 4020 | |
| 4021 | static void |
| 4022 | sort_files (void) |
| 4023 | { |
| 4024 | bool use_strcmp; |
| 4025 | |
| 4026 | if (sorted_file_alloc < cwd_n_used + (cwd_n_used >> 1)) |
| 4027 | { |
| 4028 | free (sorted_file); |
| 4029 | sorted_file = xinmalloc (cwd_n_used, 3 * sizeof *sorted_file); |
| 4030 | sorted_file_alloc = 3 * cwd_n_used; |
| 4031 | } |
| 4032 | |
| 4033 | initialize_ordering_vector (); |
| 4034 | |
| 4035 | update_current_files_info (); |
| 4036 | |
| 4037 | if (sort_type == sort_none) |
| 4038 | return; |
| 4039 | |
| 4040 | /* Try strcoll. If it fails, fall back on strcmp. We can't safely |
| 4041 | ignore strcoll failures, as a failing strcoll might be a |
| 4042 | comparison function that is not a total order, and if we ignored |
| 4043 | the failure this might cause qsort to dump core. */ |
| 4044 | |
| 4045 | if (! setjmp (failed_strcoll)) |
| 4046 | use_strcmp = false; /* strcoll() succeeded */ |
| 4047 | else |
| 4048 | { |
| 4049 | use_strcmp = true; |
| 4050 | affirm (sort_type != sort_version); |
| 4051 | initialize_ordering_vector (); |
| 4052 | } |
| 4053 | |
| 4054 | /* When sort_type == sort_time, use time_type as subindex. */ |
| 4055 | mpsort ((void const **) sorted_file, cwd_n_used, |
| 4056 | sort_functions[sort_type + (sort_type == sort_time ? time_type : 0)] |
| 4057 | [use_strcmp][sort_reverse] |
| 4058 | [directories_first]); |
| 4059 | } |
| 4060 | |
| 4061 | /* List all the files now in the table. */ |
| 4062 |
no test coverage detected