TianoCore EDK2 master
Loading...
Searching...
No Matches
DummyOpensslSupport.c
1
6#include <CrtLibSupport.h>
7
8int errno = 0;
9
10FILE *stderr = NULL;
11FILE *stdin = NULL;
12FILE *stdout = NULL;
13
14typedef
15 int
16(*SORT_COMPARE)(
17 IN VOID *Buffer1,
18 IN VOID *Buffer2
19 );
20
21//
22// Duplicated from EDKII BaseSortLib for qsort() wrapper
23//
25VOID
26QuickSortWorker (
27 IN OUT VOID *BufferToSort,
28 IN CONST UINTN Count,
29 IN CONST UINTN ElementSize,
30 IN SORT_COMPARE CompareFunction,
31 IN VOID *Buffer
32 )
33{
34 VOID *Pivot;
35 UINTN LoopCount;
36 UINTN NextSwapLocation;
37
38 ASSERT (BufferToSort != NULL);
39 ASSERT (CompareFunction != NULL);
40 ASSERT (Buffer != NULL);
41
42 if ((Count < 2) || (ElementSize < 1)) {
43 return;
44 }
45
46 NextSwapLocation = 0;
47
48 //
49 // Pick a pivot (we choose last element)
50 //
51 Pivot = ((UINT8 *)BufferToSort + ((Count - 1) * ElementSize));
52
53 //
54 // Now get the pivot such that all on "left" are below it
55 // and everything "right" are above it
56 //
57 for (LoopCount = 0; LoopCount < Count - 1; LoopCount++) {
58 //
59 // If the element is less than the pivot
60 //
61 if (CompareFunction ((VOID *)((UINT8 *)BufferToSort + ((LoopCount) * ElementSize)), Pivot) <= 0) {
62 //
63 // Swap
64 //
65 CopyMem (Buffer, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
66 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), (UINT8 *)BufferToSort + ((LoopCount) * ElementSize), ElementSize);
67 CopyMem ((UINT8 *)BufferToSort + ((LoopCount) * ElementSize), Buffer, ElementSize);
68
69 //
70 // Increment NextSwapLocation
71 //
72 NextSwapLocation++;
73 }
74 }
75
76 //
77 // Swap pivot to its final position (NextSwapLocation)
78 //
79 CopyMem (Buffer, Pivot, ElementSize);
80 CopyMem (Pivot, (UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), ElementSize);
81 CopyMem ((UINT8 *)BufferToSort + (NextSwapLocation * ElementSize), Buffer, ElementSize);
82
83 //
84 // Now recurse on 2 partial lists. Neither of these will have the 'pivot' element.
85 // IE list is sorted left half, pivot element, sorted right half...
86 //
87 QuickSortWorker (
88 BufferToSort,
89 NextSwapLocation,
90 ElementSize,
91 CompareFunction,
92 Buffer
93 );
94
95 QuickSortWorker (
96 (UINT8 *)BufferToSort + (NextSwapLocation + 1) * ElementSize,
97 Count - NextSwapLocation - 1,
98 ElementSize,
99 CompareFunction,
100 Buffer
101 );
102
103 return;
104}
105
106// ---------------------------------------------------------
107// Standard C Run-time Library Interface Wrapper
108// ---------------------------------------------------------
109
110//
111// -- String Manipulation Routines --
112//
113
114/* Scan a string for the last occurrence of a character */
115char *
116strrchr (
117 const char *str,
118 int c
119 )
120{
121 char *save;
122
123 for (save = NULL; ; ++str) {
124 if (*str == c) {
125 save = (char *)str;
126 }
127
128 if (*str == 0) {
129 return (save);
130 }
131 }
132}
133
134/* Compare first n bytes of string s1 with string s2, ignoring case */
135int
136strncasecmp (
137 const char *s1,
138 const char *s2,
139 size_t n
140 )
141{
142 int Val;
143
144 ASSERT (s1 != NULL);
145 ASSERT (s2 != NULL);
146
147 if (n != 0) {
148 do {
149 Val = tolower (*s1) - tolower (*s2);
150 if (Val != 0) {
151 return Val;
152 }
153
154 ++s1;
155 ++s2;
156 if (*s1 == '\0') {
157 break;
158 }
159 } while (--n != 0);
160 }
161
162 return 0;
163}
164
165/* Read formatted data from a string */
166int
167sscanf (
168 const char *buffer,
169 const char *format,
170 ...
171 )
172{
173 //
174 // Null sscanf() function implementation to satisfy the linker, since
175 // no direct functionality logic dependency in present UEFI cases.
176 //
177 return 0;
178}
179
180/* Maps errnum to an error-message string */
181char *
182strerror (
183 int errnum
184 )
185{
186 return NULL;
187}
188
189/* Computes the length of the maximum initial segment of the string pointed to by s1
190 which consists entirely of characters from the string pointed to by s2. */
191size_t
192strspn (
193 const char *s1,
194 const char *s2
195 )
196{
197 UINT8 Map[32];
198 UINT32 Index;
199 size_t Count;
200
201 for (Index = 0; Index < 32; Index++) {
202 Map[Index] = 0;
203 }
204
205 while (*s2) {
206 Map[*s2 >> 3] |= (1 << (*s2 & 7));
207 s2++;
208 }
209
210 if (*s1) {
211 Count = 0;
212 while (Map[*s1 >> 3] & (1 << (*s1 & 7))) {
213 Count++;
214 s1++;
215 }
216
217 return Count;
218 }
219
220 return 0;
221}
222
223/* Computes the length of the maximum initial segment of the string pointed to by s1
224 which consists entirely of characters not from the string pointed to by s2. */
225size_t
226strcspn (
227 const char *s1,
228 const char *s2
229 )
230{
231 UINT8 Map[32];
232 UINT32 Index;
233 size_t Count;
234
235 for (Index = 0; Index < 32; Index++) {
236 Map[Index] = 0;
237 }
238
239 while (*s2) {
240 Map[*s2 >> 3] |= (1 << (*s2 & 7));
241 s2++;
242 }
243
244 Map[0] |= 1;
245
246 Count = 0;
247 while (!(Map[*s1 >> 3] & (1 << (*s1 & 7)))) {
248 Count++;
249 s1++;
250 }
251
252 return Count;
253}
254
255char *
256strcpy (
257 char *strDest,
258 const char *strSource
259 )
260{
261 AsciiStrCpyS (strDest, AsciiStrnSizeS (strSource, MAX_STRING_SIZE - 1), strSource);
262 return strDest;
263}
264
265char *
266strncpy (
267 char *strDest,
268 const char *strSource,
269 size_t count
270 )
271{
272 UINTN DestMax = MAX_STRING_SIZE;
273
274 if (count < MAX_STRING_SIZE) {
275 DestMax = count + 1;
276 } else {
277 count = MAX_STRING_SIZE-1;
278 }
279
280 AsciiStrnCpyS (strDest, DestMax, strSource, (UINTN)count);
281
282 return strDest;
283}
284
285//
286// -- Character Classification Routines --
287//
288
289/* Determines if a particular character is a decimal-digit character */
290int
291isdigit (
292 int c
293 )
294{
295 //
296 // <digit> ::= [0-9]
297 //
298 return (('0' <= (c)) && ((c) <= '9'));
299}
300
301/* Determine if an integer represents character that is a hex digit */
302int
303isxdigit (
304 int c
305 )
306{
307 //
308 // <hexdigit> ::= [0-9] | [a-f] | [A-F]
309 //
310 return ((('0' <= (c)) && ((c) <= '9')) ||
311 (('a' <= (c)) && ((c) <= 'f')) ||
312 (('A' <= (c)) && ((c) <= 'F')));
313}
314
315/* Determines if a particular character represents a space character */
316int
317isspace (
318 int c
319 )
320{
321 //
322 // <space> ::= [ ]
323 //
324 return ((c) == ' ');
325}
326
327/* Determine if a particular character is an alphanumeric character */
328int
329isalnum (
330 int c
331 )
332{
333 //
334 // <alnum> ::= [0-9] | [a-z] | [A-Z]
335 //
336 return ((('0' <= (c)) && ((c) <= '9')) ||
337 (('a' <= (c)) && ((c) <= 'z')) ||
338 (('A' <= (c)) && ((c) <= 'Z')));
339}
340
341/* Determines if a particular character is in upper case */
342int
343isupper (
344 int c
345 )
346{
347 //
348 // <uppercase letter> := [A-Z]
349 //
350 return (('A' <= (c)) && ((c) <= 'Z'));
351}
352
353//
354// -- Data Conversion Routines --
355//
356
357/* Convert strings to a long-integer value */
358long
359strtol (
360 const char *nptr,
361 char **endptr,
362 int base
363 )
364{
365 //
366 // Null strtol() function implementation to satisfy the linker, since there is
367 // no direct functionality logic dependency in present UEFI cases.
368 //
369 return 0;
370}
371
372/* Convert strings to an unsigned long-integer value */
373unsigned long
374strtoul (
375 const char *nptr,
376 char **endptr,
377 int base
378 )
379{
380 //
381 // Null strtoul() function implementation to satisfy the linker, since there is
382 // no direct functionality logic dependency in present UEFI cases.
383 //
384 return 0;
385}
386
387/* Convert character to lowercase */
388int
389tolower (
390 int c
391 )
392{
393 if (('A' <= (c)) && ((c) <= 'Z')) {
394 return (c - ('A' - 'a'));
395 }
396
397 return (c);
398}
399
400//
401// -- Searching and Sorting Routines --
402//
403
404/* Performs a quick sort */
405void
406qsort (
407 void *base,
408 size_t num,
409 size_t width,
410 int ( *compare )(const void *, const void *)
411 )
412{
413 VOID *Buffer;
414
415 ASSERT (base != NULL);
416 ASSERT (compare != NULL);
417
418 //
419 // Use CRT-style malloc to cover BS and RT memory allocation.
420 //
421 Buffer = malloc (width);
422 ASSERT (Buffer != NULL);
423
424 //
425 // Re-use PerformQuickSort() function Implementation in EDKII BaseSortLib.
426 //
427 QuickSortWorker (base, (UINTN)num, (UINTN)width, (SORT_COMPARE)compare, Buffer);
428
429 free (Buffer);
430 return;
431}
432
433//
434// -- Process and Environment Control Routines --
435//
436
437/* Get a value from the current environment */
438char *
439getenv (
440 const char *varname
441 )
442{
443 //
444 // Null getenv() function implementation to satisfy the linker, since there is
445 // no direct functionality logic dependency in present UEFI cases.
446 //
447 return NULL;
448}
449
450/* Get a value from the current environment */
451char *
452secure_getenv (
453 const char *varname
454 )
455{
456 //
457 // Null secure_getenv() function implementation to satisfy the linker, since
458 // there is no direct functionality logic dependency in present UEFI cases.
459 //
460 // From the secure_getenv() manual: 'just like getenv() except that it
461 // returns NULL in cases where "secure execution" is required'.
462 //
463 return NULL;
464}
465
466//
467// -- Stream I/O Routines --
468//
469
470/* Write data to a stream */
471size_t
472fwrite (
473 const void *buffer,
474 size_t size,
475 size_t count,
476 FILE *stream
477 )
478{
479 return 0;
480}
481
482#ifdef __GNUC__
483
484typedef
485 VOID
486(EFIAPI *NoReturnFuncPtr)(
487 VOID
488 ) __attribute__ ((__noreturn__));
489
490STATIC
491VOID
492EFIAPI
493NopFunction (
494 VOID
495 )
496{
497}
498
499void
500abort (
501 void
502 )
503{
504 NoReturnFuncPtr NoReturnFunc;
505
506 NoReturnFunc = (NoReturnFuncPtr)NopFunction;
507
508 NoReturnFunc ();
509}
510
511#else
512
513void
514abort (
515 void
516 )
517{
518 // Do nothing
519}
520
521#endif
522
523int
524fclose (
525 FILE *f
526 )
527{
528 return 0;
529}
530
531FILE *
532fopen (
533 const char *c,
534 const char *m
535 )
536{
537 return NULL;
538}
539
540size_t
541fread (
542 void *b,
543 size_t c,
544 size_t i,
545 FILE *f
546 )
547{
548 return 0;
549}
550
551uid_t
552getuid (
553 void
554 )
555{
556 return 0;
557}
558
559uid_t
560geteuid (
561 void
562 )
563{
564 return 0;
565}
566
567gid_t
568getgid (
569 void
570 )
571{
572 return 0;
573}
574
575gid_t
576getegid (
577 void
578 )
579{
580 return 0;
581}
582
583int
584printf (
585 char const *fmt,
586 ...
587 )
588{
589 return 0;
590}
UINT64 UINTN
RETURN_STATUS EFIAPI AsciiStrnCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source, IN UINTN Length)
Definition: SafeString.c:1875
UINTN EFIAPI AsciiStrnSizeS(IN CONST CHAR8 *String, IN UINTN MaxSize)
Definition: SafeString.c:1749
RETURN_STATUS EFIAPI AsciiStrCpyS(OUT CHAR8 *Destination, IN UINTN DestMax, IN CONST CHAR8 *Source)
Definition: SafeString.c:1797
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
unsigned long long UINT64 __attribute__((aligned(8)))
Definition: ProcessorBind.h:28