]> git.proxmox.com Git - mirror_edk2.git/blob - CryptoPkg/Library/BaseCryptLib/SysCall/CrtWrapper.c
Patch from open source community for CryptoPkg to allow it to build for ARM using...
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / CrtWrapper.c
1 /** @file
2 C Run-Time Libraries (CRT) Wrapper Implementation for OpenSSL-based
3 Cryptographic Library.
4
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
10
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.
13
14 **/
15
16 #include <OpenSslSupport.h>
17
18 int errno = 0;
19
20 typedef
21 INTN
22 (*SORT_COMPARE)(
23 IN VOID *Buffer1,
24 IN VOID *Buffer2
25 );
26
27 //
28 // Duplicated from EDKII BaseSortLib for qsort() wrapper
29 //
30 STATIC
31 VOID
32 QuickSortWorker (
33 IN OUT VOID *BufferToSort,
34 IN CONST UINTN Count,
35 IN CONST UINTN ElementSize,
36 IN SORT_COMPARE CompareFunction,
37 IN VOID *Buffer
38 )
39 {
40 VOID *Pivot;
41 UINTN LoopCount;
42 UINTN NextSwapLocation;
43
44 ASSERT(BufferToSort != NULL);
45 ASSERT(CompareFunction != NULL);
46 ASSERT(Buffer != NULL);
47
48 if (Count < 2 || ElementSize < 1) {
49 return;
50 }
51
52 NextSwapLocation = 0;
53
54 //
55 // Pick a pivot (we choose last element)
56 //
57 Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));
58
59 //
60 // Now get the pivot such that all on "left" are below it
61 // and everything "right" are above it
62 //
63 for (LoopCount = 0; LoopCount < Count - 1; LoopCount++)
64 {
65 //
66 // If the element is less than the pivot
67 //
68 if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {
69 //
70 // Swap
71 //
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);
75
76 //
77 // Increment NextSwapLocation
78 //
79 NextSwapLocation++;
80 }
81 }
82 //
83 // Swap pivot to it's final position (NextSwapLocaiton)
84 //
85 CopyMem (Buffer, Pivot, ElementSize);
86 CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
87 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);
88
89 //
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...
92 //
93 QuickSortWorker (
94 BufferToSort,
95 NextSwapLocation,
96 ElementSize,
97 CompareFunction,
98 Buffer
99 );
100
101 QuickSortWorker (
102 (UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,
103 Count - NextSwapLocation - 1,
104 ElementSize,
105 CompareFunction,
106 Buffer
107 );
108
109 return;
110 }
111
112 //---------------------------------------------------------
113 // Standard C Run-time Library Interface Wrapper
114 //---------------------------------------------------------
115
116 //
117 // -- String Manipulation Routines --
118 //
119
120 /* Scan a string for the last occurrence of a character */
121 char *strrchr (const char *str, int c)
122 {
123 char * save;
124
125 for (save = NULL; ; ++str) {
126 if (*str == c) {
127 save = (char *)str;
128 }
129 if (*str == 0) {
130 return (save);
131 }
132 }
133 }
134
135 /* Read formatted data from a string */
136 int sscanf (const char *buffer, const char *format, ...)
137 {
138 //
139 // Null sscanf() function implementation to satisfy the linker, since
140 // no direct functionality logic dependency in present UEFI cases.
141 //
142 return 0;
143 }
144
145 //
146 // -- Character Classification Routines --
147 //
148
149 /* Determines if a particular character is a decimal-digit character */
150 int isdigit (int c)
151 {
152 //
153 // <digit> ::= [0-9]
154 //
155 return (('0' <= (c)) && ((c) <= '9'));
156 }
157
158 /* Determine if an integer represents character that is a hex digit */
159 int isxdigit (int c)
160 {
161 //
162 // <hexdigit> ::= [0-9] | [a-f] | [A-F]
163 //
164 return ((('0' <= (c)) && ((c) <= '9')) ||
165 (('a' <= (c)) && ((c) <= 'f')) ||
166 (('A' <= (c)) && ((c) <= 'F')));
167 }
168
169 /* Determines if a particular character represents a space character */
170 int isspace (int c)
171 {
172 //
173 // <space> ::= [ ]
174 //
175 return ((c) == ' ');
176 }
177
178 /* Determine if a particular character is an alphanumeric character */
179 int isalnum (int c)
180 {
181 //
182 // <alnum> ::= [0-9] | [a-z] | [A-Z]
183 //
184 return ((('0' <= (c)) && ((c) <= '9')) ||
185 (('a' <= (c)) && ((c) <= 'z')) ||
186 (('A' <= (c)) && ((c) <= 'Z')));
187 }
188
189 /* Determines if a particular character is in upper case */
190 int isupper (int c)
191 {
192 //
193 // <uppercase letter> := [A-Z]
194 //
195 return (('A' <= (c)) && ((c) <= 'Z'));
196 }
197
198 //
199 // -- Data Conversion Routines --
200 //
201
202 /* Convert strings to a long-integer value */
203 long strtol (const char *nptr, char **endptr, int base)
204 {
205 //
206 // Null strtol() function implementation to satisfy the linker, since there is
207 // no direct functionality logic dependency in present UEFI cases.
208 //
209 return 0;
210 }
211
212 /* Convert strings to an unsigned long-integer value */
213 unsigned long strtoul (const char *nptr, char **endptr, int base)
214 {
215 //
216 // Null strtoul() function implementation to satisfy the linker, since there is
217 // no direct functionality logic dependency in present UEFI cases.
218 //
219 return 0;
220 }
221
222 /* Convert character to lowercase */
223 int tolower (int c)
224 {
225 if (('A' <= (c)) && ((c) <= 'Z')) {
226 return (c - ('A' - 'a'));
227 }
228 return (c);
229 }
230
231 //
232 // -- Searching and Sorting Routines --
233 //
234
235 /* Performs a quick sort */
236 void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, const void *))
237 {
238 VOID *Buffer;
239
240 ASSERT (base != NULL);
241 ASSERT (compare != NULL);
242
243 Buffer = AllocatePool (width);
244 ASSERT (Buffer != NULL);
245
246 //
247 // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
248 //
249 QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);
250
251 FreePool (Buffer);
252 return;
253 }
254
255 //
256 // -- Process and Environment Control Routines --
257 //
258
259 /* Get a value from the current environment */
260 char *getenv (const char *varname)
261 {
262 //
263 // Null getenv() function implementation to satisfy the linker, since there is
264 // no direct functionality logic dependency in present UEFI cases.
265 //
266 return NULL;
267 }
268
269 //
270 // -- Stream I/O Routines --
271 //
272
273 /* Write formatted output using a pointer to a list of arguments */
274 int vfprintf (FILE *stream, const char *format, VA_LIST arg)
275 {
276 return 0;
277 }
278
279 /* Write data to a stream */
280 size_t fwrite (const void *buffer, size_t size, size_t count, FILE *stream)
281 {
282 return 0;
283 }
284
285 //
286 // -- Dummy OpenSSL Support Routines --
287 //
288
289 int BIO_printf (void *bio, const char *format, ...)
290 {
291 return 0;
292 }
293
294 int BIO_snprintf(char *buf, size_t n, const char *format, ...)
295 {
296 return 0;
297 }
298
299 void *UI_OpenSSL(void)
300 {
301 return NULL;
302 }
303
304 int X509_load_cert_file (VOID *ctx, const char *file, int type)
305 {
306 return 0;
307 }
308
309 int X509_load_crl_file (VOID *ctx, const char *file, int type)
310 {
311 return 0;
312 }
313
314 int chmod (const char *c, mode_t m)
315 {
316 return -1;
317 }
318
319 int close (int f)
320 {
321 return -1;
322 }
323
324 void closelog (void)
325 {
326
327 }
328
329 void exit (int e)
330 {
331
332 }
333
334 int fclose (FILE *f)
335 {
336 return 0;
337 }
338
339 FILE *fopen (const char *c, const char *m)
340 {
341 return NULL;
342 }
343
344 size_t fread (void *b, size_t c, size_t i, FILE *f)
345 {
346 return 0;
347 }
348
349 int fprintf (FILE *f, const char *s, ...)
350 {
351 return 0;
352 }
353
354 uid_t getuid (void)
355 {
356 return 0;
357 }
358
359 uid_t geteuid (void)
360 {
361 return 0;
362 }
363
364 gid_t getgid (void)
365 {
366 return 0;
367 }
368
369 gid_t getegid (void)
370 {
371 return 0;
372 }
373
374 off_t lseek (int a, off_t o, int d)
375 {
376 return 0;
377 }
378
379 void openlog (const char *c, int a, int b)
380 {
381
382 }
383
384 ssize_t read (int f, void *b, size_t c)
385 {
386 return 0;
387 }
388
389 int stat (const char *c, struct stat *s)
390 {
391 return -1;
392 }
393
394 int strcasecmp (const char *c, const char *s)
395 {
396 return 0;
397 }
398
399 int strncasecmp (const char *c, const char *s, size_t l)
400 {
401 return 0;
402 }
403
404 void syslog (int a, const char *c, ...)
405 {
406
407 }
408
409 ssize_t write (int f, const void *b, size_t l)
410 {
411 return 0;
412 }