--- /dev/null
+/** @file\r
+ C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based\r
+ Cryptographic Library.\r
+\r
+Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution. The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <OpenSslSupport.h>\r
+\r
+typedef\r
+INTN\r
+(*SORT_COMPARE)(\r
+ IN VOID *Buffer1,\r
+ IN VOID *Buffer2\r
+ );\r
+\r
+//\r
+// Duplicated from EDKII BaseSortLib for qsort() wrapper\r
+//\r
+STATIC\r
+VOID\r
+QuickSortWorker (\r
+ IN OUT VOID *BufferToSort,\r
+ IN CONST UINTN Count,\r
+ IN CONST UINTN ElementSize,\r
+ IN SORT_COMPARE CompareFunction,\r
+ IN VOID *Buffer\r
+ )\r
+{\r
+ VOID *Pivot;\r
+ UINTN LoopCount;\r
+ UINTN NextSwapLocation;\r
+\r
+ ASSERT(BufferToSort != NULL);\r
+ ASSERT(CompareFunction != NULL);\r
+ ASSERT(Buffer != NULL);\r
+\r
+ if (Count < 2 || ElementSize < 1) {\r
+ return;\r
+ }\r
+\r
+ NextSwapLocation = 0;\r
+\r
+ //\r
+ // Pick a pivot (we choose last element)\r
+ //\r
+ Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));\r
+\r
+ //\r
+ // Now get the pivot such that all on "left" are below it\r
+ // and everything "right" are above it\r
+ //\r
+ for (LoopCount = 0; LoopCount < Count - 1; LoopCount++)\r
+ {\r
+ //\r
+ // If the element is less than the pivot\r
+ //\r
+ if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {\r
+ //\r
+ // Swap\r
+ //\r
+ CopyMem (Buffer, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);\r
+ CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), (UINT8 *)BufferToSort + ((LoopCount) * ElementSize), ElementSize);\r
+ CopyMem ((UINT8 *)BufferToSort + ((LoopCount) * ElementSize), Buffer, ElementSize);\r
+\r
+ //\r
+ // Increment NextSwapLocation\r
+ //\r
+ NextSwapLocation++;\r
+ }\r
+ }\r
+ //\r
+ // Swap pivot to it's final position (NextSwapLocaiton)\r
+ //\r
+ CopyMem (Buffer, Pivot, ElementSize);\r
+ CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);\r
+ CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);\r
+\r
+ //\r
+ // Now recurse on 2 paritial lists. Neither of these will have the 'pivot' element.\r
+ // IE list is sorted left half, pivot element, sorted right half...\r
+ //\r
+ QuickSortWorker (\r
+ BufferToSort,\r
+ NextSwapLocation,\r
+ ElementSize,\r
+ CompareFunction,\r
+ Buffer\r
+ );\r
+\r
+ QuickSortWorker (\r
+ (UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,\r
+ Count - NextSwapLocation - 1,\r
+ ElementSize,\r
+ CompareFunction,\r
+ Buffer\r
+ );\r
+\r
+ return;\r
+}\r
+\r
+//---------------------------------------------------------\r
+// Standard C Run-time Library Interface Wrapper\r
+//---------------------------------------------------------\r
+\r
+//\r
+// -- String Manipulation Routines --\r
+//\r
+\r
+/* Scan a string for the last occurrence of a character */\r
+char *strrchr (const char *str, int c)\r
+{\r
+ char * save;\r
+\r
+ for (save = NULL; ; ++str) {\r
+ if (*str == c) {\r
+ save = (char *)str;\r
+ }\r
+ if (*str == 0) {\r
+ return (save);\r
+ }\r
+ }\r
+}\r
+\r
+/* Read formatted data from a string */\r
+int sscanf (const char *buffer, const char *format, ...)\r
+{\r
+ //\r
+ // Null sscanf() function implementation to satisfy the linker, since\r
+ // no direct functionality logic dependency in present UEFI cases.\r
+ //\r
+ return 0;\r
+}\r
+\r
+//\r
+// -- Character Classification Routines --\r
+//\r
+\r
+/* Determines if a particular character is a decimal-digit character */\r
+int isdigit (int c)\r
+{\r
+ //\r
+ // <digit> ::= [0-9]\r
+ //\r
+ return (('0' <= (c)) && ((c) <= '9'));\r
+}\r
+\r
+/* Determine if an integer represents character that is a hex digit */\r
+int isxdigit (int c)\r
+{\r
+ //\r
+ // <hexdigit> ::= [0-9] | [a-f] | [A-F]\r
+ //\r
+ return ((('0' <= (c)) && ((c) <= '9')) ||\r
+ (('a' <= (c)) && ((c) <= 'f')) ||\r
+ (('A' <= (c)) && ((c) <= 'F')));\r
+}\r
+\r
+/* Determines if a particular character represents a space character */\r
+int isspace (int c)\r
+{\r
+ //\r
+ // <space> ::= [ ]\r
+ //\r
+ return ((c) == ' ');\r
+}\r
+\r
+/* Determine if a particular character is an alphanumeric character */\r
+int isalnum (int c)\r
+{\r
+ //\r
+ // <alnum> ::= [0-9] | [a-z] | [A-Z]\r
+ //\r
+ return ((('0' <= (c)) && ((c) <= '9')) ||\r
+ (('a' <= (c)) && ((c) <= 'z')) ||\r
+ (('A' <= (c)) && ((c) <= 'Z')));\r
+}\r
+\r
+/* Determines if a particular character is in upper case */\r
+int isupper (int c)\r
+{\r
+ //\r
+ // <uppercase letter> := [A-Z]\r
+ //\r
+ return (('A' <= (c)) && ((c) <= 'Z'));\r
+}\r
+\r
+//\r
+// -- Data Conversion Routines --\r
+//\r
+\r
+/* Convert strings to a long-integer value */\r
+long strtol (const char *nptr, char **endptr, int base)\r
+{\r
+ //\r
+ // Null strtol() function implementation to satisfy the linker, since there is\r
+ // no direct functionality logic dependency in present UEFI cases.\r
+ //\r
+ return 0;\r
+}\r
+\r
+/* Convert strings to an unsigned long-integer value */\r
+unsigned long strtoul (const char *nptr, char **endptr, int base)\r
+{\r
+ //\r
+ // Null strtoul() function implementation to satisfy the linker, since there is\r
+ // no direct functionality logic dependency in present UEFI cases.\r
+ //\r
+ return 0;\r
+}\r
+\r
+/* Convert character to lowercase */\r
+int tolower (int c)\r
+{\r
+ if (('A' <= (c)) && ((c) <= 'Z')) {\r
+ return (c - ('A' - 'a'));\r
+ }\r
+ return (c);\r
+}\r
+\r
+//\r
+// -- Searching and Sorting Routines --\r
+//\r
+\r
+/* Performs a quick sort */\r
+void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))\r
+{\r
+ VOID *Buffer;\r
+\r
+ ASSERT (base != NULL);\r
+ ASSERT (compare != NULL);\r
+\r
+ Buffer = AllocatePool (width);\r
+ ASSERT (Buffer != NULL);\r
+\r
+ //\r
+ // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.\r
+ //\r
+ QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r
+\r
+ FreePool (Buffer);\r
+ return;\r
+}\r
+\r
+//\r
+// -- Process and Environment Control Routines --\r
+//\r
+\r
+/* Get a value from the current environment */\r
+char *getenv (const char *varname)\r
+{\r
+ //\r
+ // Null getenv() function implementation to satisfy the linker, since there is\r
+ // no direct functionality logic dependency in present UEFI cases.\r
+ //\r
+ return NULL;\r
+}\r
+\r
+//\r
+// -- Stream I/O Routines --\r
+//\r
+\r
+/* Write formatted output using a pointer to a list of arguments */\r
+int vfprintf (FILE *stream, const char *format, VA_LIST arg)\r
+{\r
+ return 0;\r
+}\r
+\r
+/* Write data to a stream */\r
+size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)\r
+{\r
+ return 0;\r
+}\r