]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
CryptoPkg: Fix various typos
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / CrtWrapper.c
index 1da4452d88532f199736e30a246432408beeb181..80f5c2578e21adbd482ac329cc5144cc475c19cc 100644 (file)
@@ -2,7 +2,7 @@
   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
+Copyright (c) 2009 - 2017, 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
@@ -13,10 +13,16 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \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
@@ -78,14 +84,14 @@ QuickSortWorker (
     }\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
@@ -130,6 +136,30 @@ char *strrchr (const char *str, int c)
   }\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
@@ -140,6 +170,70 @@ int sscanf (const char *buffer, const char *format, ...)
   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
@@ -238,7 +332,10 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
   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
@@ -246,7 +343,7 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
   //\r
   QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);\r
 \r
-  FreePool (Buffer);\r
+  free (Buffer);\r
   return;\r
 }\r
 \r
@@ -264,16 +361,23 @@ char *getenv (const char *varname)
   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
@@ -293,3 +397,78 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...)
 {\r
   return 0;\r
 }\r
+\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