2 C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based
\r
3 Cryptographic Library.
\r
5 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
\r
6 This program and the accompanying materials
\r
7 are licensed and made available under the terms and conditions of the BSD License
\r
8 which accompanies this distribution. The full text of the license may be found at
\r
9 http://opensource.org/licenses/bsd-license.php
\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
16 #include <OpenSslSupport.h>
\r
28 // Duplicated from EDKII BaseSortLib for qsort() wrapper
\r
33 IN OUT VOID *BufferToSort,
\r
34 IN CONST UINTN Count,
\r
35 IN CONST UINTN ElementSize,
\r
36 IN SORT_COMPARE CompareFunction,
\r
42 UINTN NextSwapLocation;
\r
44 ASSERT(BufferToSort != NULL);
\r
45 ASSERT(CompareFunction != NULL);
\r
46 ASSERT(Buffer != NULL);
\r
48 if (Count < 2 || ElementSize < 1) {
\r
52 NextSwapLocation = 0;
\r
55 // Pick a pivot (we choose last element)
\r
57 Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));
\r
60 // Now get the pivot such that all on "left" are below it
\r
61 // and everything "right" are above it
\r
63 for (LoopCount = 0; LoopCount < Count - 1; LoopCount++)
\r
66 // If the element is less than the pivot
\r
68 if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {
\r
72 CopyMem (Buffer, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
\r
73 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), (UINT8 *)BufferToSort + ((LoopCount) * ElementSize), ElementSize);
\r
74 CopyMem ((UINT8 *)BufferToSort + ((LoopCount) * ElementSize), Buffer, ElementSize);
\r
77 // Increment NextSwapLocation
\r
83 // Swap pivot to it's final position (NextSwapLocaiton)
\r
85 CopyMem (Buffer, Pivot, ElementSize);
\r
86 CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
\r
87 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);
\r
90 // Now recurse on 2 paritial lists. Neither of these will have the 'pivot' element.
\r
91 // IE list is sorted left half, pivot element, sorted right half...
\r
102 (UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,
\r
103 Count - NextSwapLocation - 1,
\r
112 //---------------------------------------------------------
\r
113 // Standard C Run-time Library Interface Wrapper
\r
114 //---------------------------------------------------------
\r
117 // -- String Manipulation Routines --
\r
120 /* Scan a string for the last occurrence of a character */
\r
121 char *strrchr (const char *str, int c)
\r
125 for (save = NULL; ; ++str) {
\r
127 save = (char *)str;
\r
135 /* Read formatted data from a string */
\r
136 int sscanf (const char *buffer, const char *format, ...)
\r
139 // Null sscanf() function implementation to satisfy the linker, since
\r
140 // no direct functionality logic dependency in present UEFI cases.
\r
146 // -- Character Classification Routines --
\r
149 /* Determines if a particular character is a decimal-digit character */
\r
150 int isdigit (int c)
\r
153 // <digit> ::= [0-9]
\r
155 return (('0' <= (c)) && ((c) <= '9'));
\r
158 /* Determine if an integer represents character that is a hex digit */
\r
159 int isxdigit (int c)
\r
162 // <hexdigit> ::= [0-9] | [a-f] | [A-F]
\r
164 return ((('0' <= (c)) && ((c) <= '9')) ||
\r
165 (('a' <= (c)) && ((c) <= 'f')) ||
\r
166 (('A' <= (c)) && ((c) <= 'F')));
\r
169 /* Determines if a particular character represents a space character */
\r
170 int isspace (int c)
\r
175 return ((c) == ' ');
\r
178 /* Determine if a particular character is an alphanumeric character */
\r
179 int isalnum (int c)
\r
182 // <alnum> ::= [0-9] | [a-z] | [A-Z]
\r
184 return ((('0' <= (c)) && ((c) <= '9')) ||
\r
185 (('a' <= (c)) && ((c) <= 'z')) ||
\r
186 (('A' <= (c)) && ((c) <= 'Z')));
\r
189 /* Determines if a particular character is in upper case */
\r
190 int isupper (int c)
\r
193 // <uppercase letter> := [A-Z]
\r
195 return (('A' <= (c)) && ((c) <= 'Z'));
\r
199 // -- Data Conversion Routines --
\r
202 /* Convert strings to a long-integer value */
\r
203 long strtol (const char *nptr, char **endptr, int base)
\r
206 // Null strtol() function implementation to satisfy the linker, since there is
\r
207 // no direct functionality logic dependency in present UEFI cases.
\r
212 /* Convert strings to an unsigned long-integer value */
\r
213 unsigned long strtoul (const char *nptr, char **endptr, int base)
\r
216 // Null strtoul() function implementation to satisfy the linker, since there is
\r
217 // no direct functionality logic dependency in present UEFI cases.
\r
222 /* Convert character to lowercase */
\r
223 int tolower (int c)
\r
225 if (('A' <= (c)) && ((c) <= 'Z')) {
\r
226 return (c - ('A' - 'a'));
\r
232 // -- Searching and Sorting Routines --
\r
235 /* Performs a quick sort */
\r
236 void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))
\r
240 ASSERT (base != NULL);
\r
241 ASSERT (compare != NULL);
\r
243 Buffer = AllocatePool (width);
\r
244 ASSERT (Buffer != NULL);
\r
247 // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
\r
249 QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);
\r
256 // -- Process and Environment Control Routines --
\r
259 /* Get a value from the current environment */
\r
260 char *getenv (const char *varname)
\r
263 // Null getenv() function implementation to satisfy the linker, since there is
\r
264 // no direct functionality logic dependency in present UEFI cases.
\r
270 // -- Stream I/O Routines --
\r
273 /* Write formatted output using a pointer to a list of arguments */
\r
274 int vfprintf (FILE *stream, const char *format, VA_LIST arg)
\r
279 /* Write data to a stream */
\r
280 size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)
\r
286 // -- Dummy OpenSSL Support Routines --
\r
289 int BIO_printf (void *bio, const char *format, ...)
\r
294 int BIO_snprintf(char *buf, size_t n, const char *format, ...)
\r
299 void *UI_OpenSSL(void)
\r
304 int X509_load_cert_file (VOID *ctx, const char *file, int type)
\r
309 int X509_load_crl_file (VOID *ctx, const char *file, int type)
\r
314 int chmod (const char *c, mode_t m)
\r
324 void closelog (void)
\r
334 int fclose (FILE *f)
\r
339 FILE *fopen (const char *c, const char *m)
\r
344 size_t fread (void *b, size_t c, size_t i, FILE *f)
\r
349 int fprintf (FILE *f, const char *s, ...)
\r
354 uid_t getuid (void)
\r
359 uid_t geteuid (void)
\r
364 gid_t getgid (void)
\r
369 gid_t getegid (void)
\r
374 off_t lseek (int a, off_t o, int d)
\r
379 void openlog (const char *c, int a, int b)
\r
384 ssize_t read (int f, void *b, size_t c)
\r
389 int stat (const char *c, struct stat *s)
\r
394 int strcasecmp (const char *c, const char *s)
\r
399 int strncasecmp (const char *c, const char *s, size_t l)
\r
404 void syslog (int a, const char *c, ...)
\r
409 ssize_t write (int f, const void *b, size_t l)
\r