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