TianoCore EDK2 master
Loading...
Searching...
No Matches
UefiSortLib.c
Go to the documentation of this file.
1
9#include <Uefi.h>
10
12#include <Protocol/DevicePath.h>
13
15#include <Library/BaseLib.h>
17#include <Library/DebugLib.h>
19#include <Library/SortLib.h>
21
22STATIC EFI_UNICODE_COLLATION_PROTOCOL *mUnicodeCollation = NULL;
23
24#define USL_FREE_NON_NULL(Pointer) \
25{ \
26 if ((Pointer) != NULL) { \
27 FreePool((Pointer)); \
28 (Pointer) = NULL; \
29 } \
30}
31
50VOID
51EFIAPI
53 IN OUT VOID *BufferToSort,
54 IN CONST UINTN Count,
55 IN CONST UINTN ElementSize,
56 IN SORT_COMPARE CompareFunction
57 )
58{
59 VOID *Buffer;
60
61 ASSERT (BufferToSort != NULL);
62 ASSERT (CompareFunction != NULL);
63
64 Buffer = AllocateZeroPool (ElementSize);
65 ASSERT (Buffer != NULL);
66
67 QuickSort (
68 BufferToSort,
69 Count,
70 ElementSize,
71 CompareFunction,
72 Buffer
73 );
74
75 FreePool (Buffer);
76 return;
77}
78
89INTN
90EFIAPI
92 IN CONST VOID *Buffer1,
93 IN CONST VOID *Buffer2
94 )
95{
96 EFI_DEVICE_PATH_PROTOCOL *DevicePath1;
97 EFI_DEVICE_PATH_PROTOCOL *DevicePath2;
98 CHAR16 *TextPath1;
99 CHAR16 *TextPath2;
100 EFI_STATUS Status;
101 INTN RetVal;
102
103 DevicePath1 = *(EFI_DEVICE_PATH_PROTOCOL **)Buffer1;
104 DevicePath2 = *(EFI_DEVICE_PATH_PROTOCOL **)Buffer2;
105
106 if (DevicePath1 == NULL) {
107 if (DevicePath2 == NULL) {
108 return 0;
109 }
110
111 return -1;
112 }
113
114 if (DevicePath2 == NULL) {
115 return 1;
116 }
117
118 if (mUnicodeCollation == NULL) {
119 Status = gBS->LocateProtocol (
120 &gEfiUnicodeCollation2ProtocolGuid,
121 NULL,
122 (VOID **)&mUnicodeCollation
123 );
124
125 ASSERT_EFI_ERROR (Status);
126 }
127
128 TextPath1 = ConvertDevicePathToText (
129 DevicePath1,
130 FALSE,
131 FALSE
132 );
133
134 TextPath2 = ConvertDevicePathToText (
135 DevicePath2,
136 FALSE,
137 FALSE
138 );
139
140 if (TextPath1 == NULL) {
141 RetVal = -1;
142 } else if (TextPath2 == NULL) {
143 RetVal = 1;
144 } else {
145 RetVal = mUnicodeCollation->StriColl (
146 mUnicodeCollation,
147 TextPath1,
148 TextPath2
149 );
150 }
151
152 USL_FREE_NON_NULL (TextPath1);
153 USL_FREE_NON_NULL (TextPath2);
154
155 return (RetVal);
156}
157
168INTN
169EFIAPI
171 IN CONST VOID *Buffer1,
172 IN CONST VOID *Buffer2
173 )
174{
175 EFI_STATUS Status;
176
177 if (mUnicodeCollation == NULL) {
178 Status = gBS->LocateProtocol (
179 &gEfiUnicodeCollation2ProtocolGuid,
180 NULL,
181 (VOID **)&mUnicodeCollation
182 );
183
184 ASSERT_EFI_ERROR (Status);
185 }
186
187 return (mUnicodeCollation->StriColl (
188 mUnicodeCollation,
189 *(CHAR16 **)Buffer1,
190 *(CHAR16 **)Buffer2
191 ));
192}
193
204INTN
205EFIAPI
207 IN CONST VOID *Buffer1,
208 IN CONST VOID *Buffer2
209 )
210{
211 return (StrCmp (
212 *(CHAR16 **)Buffer1,
213 *(CHAR16 **)Buffer2
214 ));
215}
UINT64 UINTN
INT64 INTN
INTN EFIAPI StrCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
Definition: String.c:109
VOID EFIAPI QuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN BASE_SORT_COMPARE CompareFunction, OUT VOID *BufferOneElement)
Definition: QuickSort.c:36
CHAR16 *EFIAPI ConvertDevicePathToText(IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN DisplayOnly, IN BOOLEAN AllowShortcuts)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_BOOT_SERVICES * gBS
VOID EFIAPI PerformQuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN SORT_COMPARE CompareFunction)
Definition: UefiSortLib.c:52
INTN EFIAPI StringNoCaseCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
Definition: UefiSortLib.c:170
INTN EFIAPI DevicePathCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
Definition: UefiSortLib.c:91
INTN EFIAPI StringCompare(IN CONST VOID *Buffer1, IN CONST VOID *Buffer2)
Definition: UefiSortLib.c:206