2 C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based
\r
3 Cryptographic Library.
\r
5 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
\r
6 This program and the accompanying materials
\r
7 are licensed and made available under the terms and conditions of the BSD License
\r
8 which accompanies this distribution. The full text of the license may be found at
\r
9 http://opensource.org/licenses/bsd-license.php
\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
16 #include <OpenSslSupport.h>
\r
26 // Duplicated from EDKII BaseSortLib for qsort() wrapper
\r
31 IN OUT VOID *BufferToSort,
\r
32 IN CONST UINTN Count,
\r
33 IN CONST UINTN ElementSize,
\r
34 IN SORT_COMPARE CompareFunction,
\r
40 UINTN NextSwapLocation;
\r
42 ASSERT(BufferToSort != NULL);
\r
43 ASSERT(CompareFunction != NULL);
\r
44 ASSERT(Buffer != NULL);
\r
46 if (Count < 2 || ElementSize < 1) {
\r
50 NextSwapLocation = 0;
\r
53 // Pick a pivot (we choose last element)
\r
55 Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));
\r
58 // Now get the pivot such that all on "left" are below it
\r
59 // and everything "right" are above it
\r
61 for (LoopCount = 0; LoopCount < Count - 1; LoopCount++)
\r
64 // If the element is less than the pivot
\r
66 if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {
\r
70 CopyMem (Buffer, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
\r
71 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), (UINT8 *)BufferToSort + ((LoopCount) * ElementSize), ElementSize);
\r
72 CopyMem ((UINT8 *)BufferToSort + ((LoopCount) * ElementSize), Buffer, ElementSize);
\r
75 // Increment NextSwapLocation
\r
81 // Swap pivot to it's final position (NextSwapLocaiton)
\r
83 CopyMem (Buffer, Pivot, ElementSize);
\r
84 CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
\r
85 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);
\r
88 // Now recurse on 2 paritial lists. Neither of these will have the 'pivot' element.
\r
89 // IE list is sorted left half, pivot element, sorted right half...
\r
100 (UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,
\r
101 Count - NextSwapLocation - 1,
\r
110 //---------------------------------------------------------
\r
111 // Standard C Run-time Library Interface Wrapper
\r
112 //---------------------------------------------------------
\r
115 // -- String Manipulation Routines --
\r
118 /* Scan a string for the last occurrence of a character */
\r
119 char *strrchr (const char *str, int c)
\r
123 for (save = NULL; ; ++str) {
\r
125 save = (char *)str;
\r
133 /* Read formatted data from a string */
\r
134 int sscanf (const char *buffer, const char *format, ...)
\r
137 // Null sscanf() function implementation to satisfy the linker, since
\r
138 // no direct functionality logic dependency in present UEFI cases.
\r
144 // -- Character Classification Routines --
\r
147 /* Determines if a particular character is a decimal-digit character */
\r
148 int isdigit (int c)
\r
151 // <digit> ::= [0-9]
\r
153 return (('0' <= (c)) && ((c) <= '9'));
\r
156 /* Determine if an integer represents character that is a hex digit */
\r
157 int isxdigit (int c)
\r
160 // <hexdigit> ::= [0-9] | [a-f] | [A-F]
\r
162 return ((('0' <= (c)) && ((c) <= '9')) ||
\r
163 (('a' <= (c)) && ((c) <= 'f')) ||
\r
164 (('A' <= (c)) && ((c) <= 'F')));
\r
167 /* Determines if a particular character represents a space character */
\r
168 int isspace (int c)
\r
173 return ((c) == ' ');
\r
176 /* Determine if a particular character is an alphanumeric character */
\r
177 int isalnum (int c)
\r
180 // <alnum> ::= [0-9] | [a-z] | [A-Z]
\r
182 return ((('0' <= (c)) && ((c) <= '9')) ||
\r
183 (('a' <= (c)) && ((c) <= 'z')) ||
\r
184 (('A' <= (c)) && ((c) <= 'Z')));
\r
187 /* Determines if a particular character is in upper case */
\r
188 int isupper (int c)
\r
191 // <uppercase letter> := [A-Z]
\r
193 return (('A' <= (c)) && ((c) <= 'Z'));
\r
197 // -- Data Conversion Routines --
\r
200 /* Convert strings to a long-integer value */
\r
201 long strtol (const char *nptr, char **endptr, int base)
\r
204 // Null strtol() function implementation to satisfy the linker, since there is
\r
205 // no direct functionality logic dependency in present UEFI cases.
\r
210 /* Convert strings to an unsigned long-integer value */
\r
211 unsigned long strtoul (const char *nptr, char **endptr, int base)
\r
214 // Null strtoul() function implementation to satisfy the linker, since there is
\r
215 // no direct functionality logic dependency in present UEFI cases.
\r
220 /* Convert character to lowercase */
\r
221 int tolower (int c)
\r
223 if (('A' <= (c)) && ((c) <= 'Z')) {
\r
224 return (c - ('A' - 'a'));
\r
230 // -- Searching and Sorting Routines --
\r
233 /* Performs a quick sort */
\r
234 void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))
\r
238 ASSERT (base != NULL);
\r
239 ASSERT (compare != NULL);
\r
241 Buffer = AllocatePool (width);
\r
242 ASSERT (Buffer != NULL);
\r
245 // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
\r
247 QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);
\r
254 // -- Process and Environment Control Routines --
\r
257 /* Get a value from the current environment */
\r
258 char *getenv (const char *varname)
\r
261 // Null getenv() function implementation to satisfy the linker, since there is
\r
262 // no direct functionality logic dependency in present UEFI cases.
\r
268 // -- Stream I/O Routines --
\r
271 /* Write formatted output using a pointer to a list of arguments */
\r
272 int vfprintf (FILE *stream, const char *format, VA_LIST arg)
\r
277 /* Write data to a stream */
\r
278 size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)
\r
284 // -- Dummy OpenSSL Support Routines --
\r
287 int BIO_printf (void *bio, const char *format, ...)
\r
292 int BIO_snprintf(char *buf, size_t n, const char *format, ...)
\r
297 void *UI_OpenSSL(void)
\r