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
\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
+/* 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
// -- 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
-{\r
- return NULL;\r
-}\r
+#ifdef __GNUC__\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
+typedef\r
+VOID\r
+(EFIAPI *NoReturnFuncPtr)(\r
+ VOID\r
+ ) __attribute__((__noreturn__));\r
\r
-int chmod (const char *c, mode_t m)\r
+STATIC\r
+VOID\r
+EFIAPI\r
+NopFunction (\r
+ VOID\r
+ )\r
{\r
- return -1;\r
}\r
\r
-int close (int f)\r
+void abort (void)\r
{\r
- return -1;\r
-}\r
+ NoReturnFuncPtr NoReturnFunc;\r
\r
-void closelog (void)\r
-{\r
+ NoReturnFunc = (NoReturnFuncPtr) NopFunction;\r
\r
+ NoReturnFunc ();\r
}\r
\r
-void exit (int e)\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
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
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