1 /** @file
2 
3   Module to rewrite stdlib references within Oniguruma
4 
5   (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP<BR>
6 
7   SPDX-License-Identifier: BSD-2-Clause-Patent
8 **/
9 #ifndef ONIGURUMA_UEFI_PORT_H
10 #define ONIGURUMA_UEFI_PORT_H
11 
12 #include <Library/MemoryAllocationLib.h>
13 #include <Library/PrintLib.h>
14 #include <Library/BaseMemoryLib.h>
15 #include <Library/BaseLib.h>
16 #include <Library/DebugLib.h>
17 
18 #undef _WIN32
19 #define P_(args) args
20 
21 #define SIZEOF_LONG sizeof(long)
22 #define SIZEOF_INT  sizeof(int)
23 typedef UINTN size_t;
24 
25 #define malloc(n) AllocatePool(n)
26 #define calloc(n,s) AllocateZeroPool((n)*(s))
27 
28 #define free(p)             \
29   do {                      \
30     VOID *EvalOnce;         \
31                             \
32     EvalOnce = (p);         \
33     if (EvalOnce != NULL) { \
34       FreePool (EvalOnce);  \
35     }                       \
36   } while (FALSE)
37 
38 #define realloc(OldPtr,NewSize,OldSize) ReallocatePool(OldSize,NewSize,OldPtr)
39 #define xmemmove(Dest,Src,Length) CopyMem(Dest,Src,Length)
40 #define xmemcpy(Dest,Src,Length) CopyMem(Dest,Src,Length)
41 #define xmemset(Buffer,Value,Length) SetMem(Buffer,Length,Value)
42 
43 #define va_init_list(a,b) VA_START(a,b)
44 #define va_list VA_LIST
45 #define va_arg(a,b) VA_ARG(a,b)
46 #define va_end(a) VA_END(a)
47 
48 #define FILE VOID
49 #define stdout NULL
50 #define fprintf(...)
51 #define fputs(a,b)
52 #define vsnprintf (int)AsciiVSPrint
53 #define _vsnprintf vsnprintf
54 
55 #define setlocale(a,b)
56 #define LC_ALL 0
57 
58 #define MAX_STRING_SIZE 0x1000
59 #define strlen_s(String,MaxSize)            AsciiStrnLenS (String, MaxSize)
60 #define strcat_s(Dest,MaxSize,Src)          AsciiStrCatS (Dest, MaxSize, Src)
61 #define strncpy_s(Dest,MaxSize,Src,Length)  AsciiStrnCpyS (Dest, MaxSize, Src, Length)
62 #define strcmp                              OnigStrCmp
63 
64 int OnigStrCmp (char* Str1, char* Str2);
65 
66 int EFIAPI sprintf_s (char *str, size_t sizeOfBuffer, char const *fmt, ...);
67 
68 #define exit(n) ASSERT(FALSE);
69 
70 #endif // !ONIGURUMA_UEFI_PORT_H
71