diff options
author | Lennart Poettering <lennart@poettering.net> | 2021-09-20 14:07:42 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2021-09-23 17:23:45 +0200 |
commit | 80b2f4d92ce4d7a52cbfb9b5efdcff96366fc37a (patch) | |
tree | 0454c5bbdcb7780b36da0d1733c732adf2862fef /src/boot/efi/util.c | |
parent | c6dfe36044879b77fff49dd235ae168a4ab60024 (diff) | |
download | systemd-80b2f4d92ce4d7a52cbfb9b5efdcff96366fc37a.tar.gz |
boot: generalize sorting code
Let's make this generic, so that we can reuse it elsewhere later.
Diffstat (limited to 'src/boot/efi/util.c')
-rw-r--r-- | src/boot/efi/util.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/boot/efi/util.c b/src/boot/efi/util.c index 68053c2c39..e500069d51 100644 --- a/src/boot/efi/util.c +++ b/src/boot/efi/util.c @@ -531,6 +531,36 @@ VOID clear_screen(UINTN attr) { uefi_call_wrapper(ST->ConOut->ClearScreen, 1, ST->ConOut); } +void sort_pointer_array( + VOID **array, + UINTN n_members, + compare_pointer_func_t compare) { + + assert(array || n_members == 0); + assert(compare); + + if (n_members <= 1) + return; + + for (UINTN i = 1; i < n_members; i++) { + BOOLEAN more = FALSE; + + for (UINTN k = 0; k < n_members - i; k++) { + void *entry; + + if (compare(array[k], array[k+1]) <= 0) + continue; + + entry = array[k]; + array[k] = array[k+1]; + array[k+1] = entry; + more = TRUE; + } + if (!more) + break; + } +} + EFI_STATUS get_file_info_harder( EFI_FILE_HANDLE handle, EFI_FILE_INFO **ret, |