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  This program and the accompanying materials are licensed and made available
8  under the terms and conditions of the BSD License that accompanies this
9  distribution.  The full text of the license may be found at
10  http://opensource.org/licenses/bsd-license.php.
11
12  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
13  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14**/
15#ifndef ONIGURUMA_UEFI_PORT_H
16#define ONIGURUMA_UEFI_PORT_H
17
18#include <Library/MemoryAllocationLib.h>
19#include <Library/PrintLib.h>
20#include <Library/BaseMemoryLib.h>
21#include <Library/BaseLib.h>
22#include <Library/DebugLib.h>
23
24#undef _WIN32
25#define P_(args) args
26
27#define SIZEOF_LONG sizeof(long)
28#define SIZEOF_INT  sizeof(int)
29typedef UINTN size_t;
30
31#define malloc(n) AllocatePool(n)
32#define calloc(n,s) AllocateZeroPool((n)*(s))
33
34#define free(p)             \
35  do {                      \
36    VOID *EvalOnce;         \
37                            \
38    EvalOnce = (p);         \
39    if (EvalOnce != NULL) { \
40      FreePool (EvalOnce);  \
41    }                       \
42  } while (FALSE)
43
44#define realloc(OldPtr,NewSize,OldSize) ReallocatePool(OldSize,NewSize,OldPtr)
45#define xmemmove(Dest,Src,Length) CopyMem(Dest,Src,Length)
46#define xmemcpy(Dest,Src,Length) CopyMem(Dest,Src,Length)
47#define xmemset(Buffer,Value,Length) SetMem(Buffer,Length,Value)
48
49#define va_init_list(a,b) VA_START(a,b)
50#define va_list VA_LIST
51#define va_arg(a,b) VA_ARG(a,b)
52#define va_end(a) VA_END(a)
53
54#define FILE VOID
55#define stdout NULL
56#define fprintf(...)
57#define fputs(a,b)
58#define vsnprintf (int)AsciiVSPrint
59#define _vsnprintf vsnprintf
60
61#define setlocale(a,b)
62#define LC_ALL 0
63
64#define MAX_STRING_SIZE 0x1000
65#define strlen_s(String,MaxSize)            AsciiStrnLenS (String, MaxSize)
66#define strcat_s(Dest,MaxSize,Src)          AsciiStrCatS (Dest, MaxSize, Src)
67#define strncpy_s(Dest,MaxSize,Src,Length)  AsciiStrnCpyS (Dest, MaxSize, Src, Length)
68#define strcmp                              OnigStrCmp
69
70int OnigStrCmp (char* Str1, char* Str2);
71
72int EFIAPI sprintf_s (char *str, size_t sizeOfBuffer, char const *fmt, ...);
73
74#define exit(n) ASSERT(FALSE);
75
76#endif // !ONIGURUMA_UEFI_PORT_H
77