2 C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based
5 Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <CrtLibSupport.h>
26 // Duplicated from EDKII BaseSortLib for qsort() wrapper
31 IN OUT VOID
*BufferToSort
,
33 IN CONST UINTN ElementSize
,
34 IN SORT_COMPARE CompareFunction
,
40 UINTN NextSwapLocation
;
42 ASSERT (BufferToSort
!= NULL
);
43 ASSERT (CompareFunction
!= NULL
);
44 ASSERT (Buffer
!= NULL
);
46 if ((Count
< 2) || (ElementSize
< 1)) {
53 // Pick a pivot (we choose last element)
55 Pivot
= ((UINT8
*)BufferToSort
+ ((Count
- 1) * ElementSize
));
58 // Now get the pivot such that all on "left" are below it
59 // and everything "right" are above it
61 for (LoopCount
= 0; LoopCount
< Count
- 1; LoopCount
++) {
63 // If the element is less than the pivot
65 if (CompareFunction ((VOID
*)((UINT8
*)BufferToSort
+ ((LoopCount
) * ElementSize
)), Pivot
) <= 0) {
69 CopyMem (Buffer
, (UINT8
*)BufferToSort
+ (NextSwapLocation
* ElementSize
), ElementSize
);
70 CopyMem ((UINT8
*)BufferToSort
+ (NextSwapLocation
* ElementSize
), (UINT8
*)BufferToSort
+ ((LoopCount
) * ElementSize
), ElementSize
);
71 CopyMem ((UINT8
*)BufferToSort
+ ((LoopCount
) * ElementSize
), Buffer
, ElementSize
);
74 // Increment NextSwapLocation
81 // Swap pivot to its final position (NextSwapLocation)
83 CopyMem (Buffer
, Pivot
, ElementSize
);
84 CopyMem (Pivot
, (UINT8
*)BufferToSort
+ (NextSwapLocation
* ElementSize
), ElementSize
);
85 CopyMem ((UINT8
*)BufferToSort
+ (NextSwapLocation
* ElementSize
), Buffer
, ElementSize
);
88 // Now recurse on 2 partial lists. Neither of these will have the 'pivot' element.
89 // IE list is sorted left half, pivot element, sorted right half...
100 (UINT8
*)BufferToSort
+ (NextSwapLocation
+ 1) * ElementSize
,
101 Count
- NextSwapLocation
- 1,
110 // ---------------------------------------------------------
111 // Standard C Run-time Library Interface Wrapper
112 // ---------------------------------------------------------
115 // -- String Manipulation Routines --
124 return ScanMem8 (str
, AsciiStrSize (str
), (UINT8
)ch
);
127 /* Scan a string for the last occurrence of a character */
136 for (save
= NULL
; ; ++str
) {
147 /* Compare first n bytes of string s1 with string s2, ignoring case */
162 Val
= tolower (*s1
) - tolower (*s2
);
178 /* Read formatted data from a string */
187 // Null sscanf() function implementation to satisfy the linker, since
188 // no direct functionality logic dependency in present UEFI cases.
193 /* Maps errnum to an error-message string */
202 /* Computes the length of the maximum initial segment of the string pointed to by s1
203 which consists entirely of characters from the string pointed to by s2. */
214 for (Index
= 0; Index
< 32; Index
++) {
219 Map
[*s2
>> 3] |= (1 << (*s2
& 7));
225 while (Map
[*s1
>> 3] & (1 << (*s1
& 7))) {
236 /* Computes the length of the maximum initial segment of the string pointed to by s1
237 which consists entirely of characters not from the string pointed to by s2. */
248 for (Index
= 0; Index
< 32; Index
++) {
253 Map
[*s2
>> 3] |= (1 << (*s2
& 7));
260 while (!(Map
[*s1
>> 3] & (1 << (*s1
& 7)))) {
270 char *restrict strDest
,
271 const char *strSource
274 AsciiStrCpyS (strDest
, MAX_STRING_SIZE
, strSource
);
279 // -- Character Classification Routines --
282 /* Determines if a particular character is a decimal-digit character */
291 return (('0' <= (c
)) && ((c
) <= '9'));
294 /* Determine if an integer represents character that is a hex digit */
301 // <hexdigit> ::= [0-9] | [a-f] | [A-F]
303 return ((('0' <= (c
)) && ((c
) <= '9')) ||
304 (('a' <= (c
)) && ((c
) <= 'f')) ||
305 (('A' <= (c
)) && ((c
) <= 'F')));
308 /* Determines if a particular character represents a space character */
320 /* Determine if a particular character is an alphanumeric character */
327 // <alnum> ::= [0-9] | [a-z] | [A-Z]
329 return ((('0' <= (c
)) && ((c
) <= '9')) ||
330 (('a' <= (c
)) && ((c
) <= 'z')) ||
331 (('A' <= (c
)) && ((c
) <= 'Z')));
334 /* Determines if a particular character is in upper case */
341 // <uppercase letter> := [A-Z]
343 return (('A' <= (c
)) && ((c
) <= 'Z'));
347 // -- Data Conversion Routines --
350 /* Convert strings to a long-integer value */
359 // Null strtol() function implementation to satisfy the linker, since there is
360 // no direct functionality logic dependency in present UEFI cases.
365 /* Convert strings to an unsigned long-integer value */
374 // Null strtoul() function implementation to satisfy the linker, since there is
375 // no direct functionality logic dependency in present UEFI cases.
380 /* Convert character to lowercase */
386 if (('A' <= (c
)) && ((c
) <= 'Z')) {
387 return (c
- ('A' - 'a'));
394 // -- Searching and Sorting Routines --
397 /* Performs a quick sort */
403 int ( *compare
)(const void *, const void *)
408 ASSERT (base
!= NULL
);
409 ASSERT (compare
!= NULL
);
412 // Use CRT-style malloc to cover BS and RT memory allocation.
414 Buffer
= malloc (width
);
415 ASSERT (Buffer
!= NULL
);
418 // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
420 QuickSortWorker (base
, (UINTN
)num
, (UINTN
)width
, (SORT_COMPARE
)compare
, Buffer
);
427 // -- Process and Environment Control Routines --
430 /* Get a value from the current environment */
437 // Null getenv() function implementation to satisfy the linker, since there is
438 // no direct functionality logic dependency in present UEFI cases.
443 /* Get a value from the current environment */
450 // Null secure_getenv() function implementation to satisfy the linker, since
451 // there is no direct functionality logic dependency in present UEFI cases.
453 // From the secure_getenv() manual: 'just like getenv() except that it
454 // returns NULL in cases where "secure execution" is required'.
460 // -- Stream I/O Routines --
463 /* Write data to a stream */
476 // -- Dummy OpenSSL Support Routines --
504 (EFIAPI
*NoReturnFuncPtr
)(
506 ) __attribute__ ((__noreturn__
));
522 NoReturnFuncPtr NoReturnFunc
;
524 NoReturnFunc
= (NoReturnFuncPtr
)NopFunction
;