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
+Copyright (c) 2009 - 2017, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
-#include <OpenSslSupport.h>\r
+#include <CrtLibSupport.h>\r
+\r
+int errno = 0;\r
+\r
+FILE *stderr = NULL;\r
+FILE *stdin = NULL;\r
+FILE *stdout = NULL;\r
\r
typedef\r
-INTN\r
+int\r
(*SORT_COMPARE)(\r
IN VOID *Buffer1,\r
IN VOID *Buffer2\r
}\r
}\r
//\r
- // Swap pivot to it's final position (NextSwapLocaiton)\r
+ // Swap pivot to its final position (NextSwapLocation)\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
+ // Now recurse on 2 partial 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
}\r
}\r
\r
+/* Compare first n bytes of string s1 with string s2, ignoring case */\r
+int strncasecmp (const char *s1, const char *s2, size_t n)\r
+{\r
+ int Val;\r
+\r
+ ASSERT(s1 != NULL);\r
+ ASSERT(s2 != NULL);\r
+\r
+ if (n != 0) {\r
+ do {\r
+ Val = tolower(*s1) - tolower(*s2);\r
+ if (Val != 0) {\r
+ return Val;\r
+ }\r
+ ++s1;\r
+ ++s2;\r
+ if (*s1 == '\0') {\r
+ break;\r
+ }\r
+ } while (--n != 0);\r
+ }\r
+ return 0;\r
+}\r
+\r
/* Read formatted data from a string */\r
int sscanf (const char *buffer, const char *format, ...)\r
{\r
return 0;\r
}\r
\r
+/* Maps errnum to an error-message string */\r
+char * strerror (int errnum)\r
+{\r
+ return NULL;\r
+}\r
+\r
+/* Computes the length of the maximum initial segment of the string pointed to by s1\r
+ which consists entirely of characters from the string pointed to by s2. */\r
+size_t strspn (const char *s1 , const char *s2)\r
+{\r
+ UINT8 Map[32];\r
+ UINT32 Index;\r
+ size_t Count;\r
+\r
+ for (Index = 0; Index < 32; Index++) {\r
+ Map[Index] = 0;\r
+ }\r
+\r
+ while (*s2) {\r
+ Map[*s2 >> 3] |= (1 << (*s2 & 7));\r
+ s2++;\r
+ }\r
+\r
+ if (*s1) {\r
+ Count = 0;\r
+ while (Map[*s1 >> 3] & (1 << (*s1 & 7))) {\r
+ Count++;\r
+ s1++;\r
+ }\r
+\r
+ return Count;\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+/* Computes the length of the maximum initial segment of the string pointed to by s1\r
+ which consists entirely of characters not from the string pointed to by s2. */\r
+size_t strcspn (const char *s1, const char *s2)\r
+{\r
+ UINT8 Map[32];\r
+ UINT32 Index;\r
+ size_t Count;\r
+\r
+ for (Index = 0; Index < 32; Index++) {\r
+ Map[Index] = 0;\r
+ }\r
+\r
+ while (*s2) {\r
+ Map[*s2 >> 3] |= (1 << (*s2 & 7));\r
+ s2++;\r
+ }\r
+\r
+ Map[0] |= 1;\r
+\r
+ Count = 0;\r
+ while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) {\r
+ Count ++;\r
+ s1++;\r
+ }\r
+\r
+ return Count;\r
+}\r
+\r
//\r
// -- Character Classification Routines --\r
//\r
ASSERT (base != NULL);\r
ASSERT (compare != NULL);\r
\r
- Buffer = AllocatePool (width);\r
+ //\r
+ // Use CRT-style malloc to cover BS and RT memory allocation.\r
+ //\r
+ Buffer = malloc (width);\r
ASSERT (Buffer != NULL);\r
\r
//\r
//\r
QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r
\r
- FreePool (Buffer);\r
+ free (Buffer);\r
return;\r
}\r
\r
return NULL;\r
}\r
\r
+/* Get a value from the current environment */\r
+char *secure_getenv (const char *varname)\r
+{\r
+ //\r
+ // Null secure_getenv() function implementation to satisfy the linker, since\r
+ // there is no direct functionality logic dependency in present UEFI cases.\r
+ //\r
+ // From the secure_getenv() manual: 'just like getenv() except that it\r
+ // returns NULL in cases where "secure execution" is required'.\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
\r
-void *UI_OpenSSL(void)\r
+#ifdef __GNUC__\r
+\r
+typedef\r
+VOID\r
+(EFIAPI *NoReturnFuncPtr)(\r
+ VOID\r
+ ) __attribute__((__noreturn__));\r
+\r
+STATIC\r
+VOID\r
+EFIAPI\r
+NopFunction (\r
+ VOID\r
+ )\r
+{\r
+}\r
+\r
+void abort (void)\r
+{\r
+ NoReturnFuncPtr NoReturnFunc;\r
+\r
+ NoReturnFunc = (NoReturnFuncPtr) NopFunction;\r
+\r
+ NoReturnFunc ();\r
+}\r
+\r
+#else\r
+\r
+void abort (void)\r
+{\r
+ // Do nothing\r
+}\r
+\r
+#endif\r
+\r
+int fclose (FILE *f)\r
+{\r
+ return 0;\r
+}\r
+\r
+FILE *fopen (const char *c, const char *m)\r
{\r
return NULL;\r
}\r
+\r
+size_t fread (void *b, size_t c, size_t i, FILE *f)\r
+{\r
+ return 0;\r
+}\r
+\r
+uid_t getuid (void)\r
+{\r
+ return 0;\r
+}\r
+\r
+uid_t geteuid (void)\r
+{\r
+ return 0;\r
+}\r
+\r
+gid_t getgid (void)\r
+{\r
+ return 0;\r
+}\r
+\r
+gid_t getegid (void)\r
+{\r
+ return 0;\r
+}\r
+\r
+int printf (char const *fmt, ...)\r
+{\r
+ return 0;\r
+}\r