| 718 | } |
| 719 | |
| 720 | void ap_core_reorder_directories(apr_pool_t *p, server_rec *s) |
| 721 | { |
| 722 | core_server_config *sconf; |
| 723 | apr_array_header_t *sec_dir; |
| 724 | struct reorder_sort_rec *sortbin; |
| 725 | int nelts; |
| 726 | ap_conf_vector_t **elts; |
| 727 | int i; |
| 728 | apr_pool_t *tmp; |
| 729 | |
| 730 | sconf = ap_get_core_module_config(s->module_config); |
| 731 | sec_dir = sconf->sec_dir; |
| 732 | nelts = sec_dir->nelts; |
| 733 | elts = (ap_conf_vector_t **)sec_dir->elts; |
| 734 | |
| 735 | if (!nelts) { |
| 736 | /* simple case of already being sorted... */ |
| 737 | /* We're not checking this condition to be fast... we're checking |
| 738 | * it to avoid trying to palloc zero bytes, which can trigger some |
| 739 | * memory debuggers to barf |
| 740 | */ |
| 741 | return; |
| 742 | } |
| 743 | |
| 744 | /* we have to allocate tmp space to do a stable sort */ |
| 745 | apr_pool_create(&tmp, p); |
| 746 | apr_pool_tag(tmp, "core_reorder_directories"); |
| 747 | sortbin = apr_palloc(tmp, sec_dir->nelts * sizeof(*sortbin)); |
| 748 | for (i = 0; i < nelts; ++i) { |
| 749 | sortbin[i].orig_index = i; |
| 750 | sortbin[i].elt = elts[i]; |
| 751 | } |
| 752 | |
| 753 | qsort(sortbin, nelts, sizeof(*sortbin), reorder_sorter); |
| 754 | |
| 755 | /* and now copy back to the original array */ |
| 756 | for (i = 0; i < nelts; ++i) { |
| 757 | elts[i] = sortbin[i].elt; |
| 758 | } |
| 759 | |
| 760 | apr_pool_destroy(tmp); |
| 761 | } |
| 762 | |
| 763 | /***************************************************************** |
| 764 | * |
no test coverage detected