]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
CryptoPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / CrtWrapper.c
index fb446b677044c35764c9e86bf1c7e8782ced1901..71a2ef34ed2bd99dc986c082199546e6a6516906 100644 (file)
@@ -2,18 +2,12 @@
   C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based\r
   Cryptographic Library.\r
 \r
-Copyright (c) 2009 - 2011, 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
@@ -22,7 +16,7 @@ FILE  *stdin  = NULL;
 FILE  *stdout = NULL;\r
 \r
 typedef\r
-INTN\r
+int\r
 (*SORT_COMPARE)(\r
   IN  VOID  *Buffer1,\r
   IN  VOID  *Buffer2\r
@@ -84,14 +78,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
@@ -136,6 +130,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
@@ -146,6 +164,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
@@ -273,16 +355,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
@@ -303,36 +392,6 @@ int BIO_snprintf(char *buf, size_t n, const char *format, ...)
   return 0;\r
 }\r
 \r
-void *UI_OpenSSL(void)\r
-{\r
-  return NULL;\r
-}\r
-\r
-int X509_load_cert_file (VOID *ctx, const char *file, int type)\r
-{\r
-  return 0;\r
-}\r
-\r
-int X509_load_crl_file (VOID *ctx, const char *file, int type)\r
-{\r
-  return 0;\r
-}\r
-\r
-int chmod (const char *c, mode_t m)\r
-{\r
-  return -1;\r
-}\r
-\r
-int close (int f)\r
-{\r
-  return -1;\r
-}\r
-\r
-void closelog (void)\r
-{\r
-\r
-}\r
-\r
 #ifdef __GNUC__\r
 \r
 typedef\r
@@ -341,7 +400,6 @@ VOID
   VOID\r
   ) __attribute__((__noreturn__));\r
 \r
-\r
 STATIC\r
 VOID\r
 EFIAPI\r
@@ -351,8 +409,7 @@ NopFunction (
 {\r
 }\r
 \r
-\r
-void exit (int e)\r
+void abort (void)\r
 {\r
   NoReturnFuncPtr NoReturnFunc;\r
 \r
@@ -363,8 +420,9 @@ void exit (int e)
 \r
 #else\r
 \r
-void exit (int e)\r
+void abort (void)\r
 {\r
+  // Do nothing\r
 }\r
 \r
 #endif\r
@@ -384,11 +442,6 @@ size_t fread (void *b, size_t c, size_t i, FILE *f)
   return 0;\r
 }\r
 \r
-int fprintf (FILE *f, const char *s, ...)\r
-{\r
-  return 0;\r
-}\r
-\r
 uid_t getuid (void)\r
 {\r
   return 0;\r
@@ -409,42 +462,7 @@ gid_t getegid (void)
   return 0;\r
 }\r
 \r
-off_t lseek (int a, off_t o, int d)\r
-{\r
-  return 0;\r
-}\r
-\r
-void openlog (const char *c, int a, int b)\r
-{\r
-\r
-}\r
-\r
-ssize_t read (int f, void *b, size_t c)\r
-{\r
-  return 0;\r
-}\r
-\r
-int stat (const char *c, struct stat *s)\r
-{\r
-  return -1;\r
-}\r
-\r
-int strcasecmp (const char *c, const char *s)\r
-{\r
-  return 0;\r
-}\r
-\r
-int strncasecmp (const char *c, const char *s, size_t l)\r
-{\r
-  return 0;\r
-}\r
-\r
-void syslog (int a, const char *c, ...)\r
-{\r
-\r
-}\r
-\r
-ssize_t write (int f, const void *b, size_t l)\r
+int printf (char const *fmt, ...)\r
 {\r
   return 0;\r
 }\r