forked from CloverHackyColor/CloverBootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatform.cpp
More file actions
executable file
·199 lines (175 loc) · 4.86 KB
/
Copy pathPlatform.cpp
File metadata and controls
executable file
·199 lines (175 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
//
// Platform.cpp
// cpp_tests
//
// Created by jief on 23.02.20.
// Copyright © 2020 JF Knudsen. All rights reserved.
//
#include "Platform.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//#include <wchar.h>
#include <locale.h>
#include <string>
#include <locale>
#include <codecvt>
#include <vector>
#include "../../../rEFIt_UEFI/cpp_foundation/unicode_conversions.h"
void CpuDeadLoop(void)
{
exit(1);
}
//
//static char *dull_replace(const char *in, const char *pattern, const char *by, char* res)
//{
//// size_t outsize = strlen(in) + 1;
// // TODO maybe avoid reallocing by counting the non-overlapping occurences of pattern
//// char *res = malloc(outsize);
// // use this to iterate over the output
// size_t resoffset = 0;
//
// const char *needle;
// while ( (needle = strstr(in, pattern)) ) {
// // copy everything up to the pattern
// memcpy(res + resoffset, in, (size_t)(needle - in));
// resoffset += (size_t)(needle - in);
//
// // skip the pattern in the input-string
// in = needle + strlen(pattern);
//
// // adjust space for replacement
//// outsize = outsize - strlen(pattern) + strlen(by);
//// res = realloc(res, outsize);
//
// // copy the pattern
// memcpy(res + resoffset, by, strlen(by));
// resoffset += strlen(by);
// }
//
// // copy the remaining input
// strcpy(res + resoffset, in);
//
// return res;
//}
//
//void DebugLog(INTN DebugMode, const char *FormatString, ...)
//{
// (void)DebugMode;
//
// char* NewFormat = (char*)alloca(strlen(FormatString)+1);
//// dull_replace(FormatString, "%a", "%s", NewFormat);
//
// va_list va;
// va_start(va, FormatString);
// vprintf(NewFormat, va);
// va_end(va);
//}
void PauseForKey(const wchar_t* msg)
{
printf("%ls", msg);
getchar();
}
UINTN StrLen(const wchar_t* String)
{
return size_of_utf_string(String);
}
UINTN StrLen(const char16_t* String)
{
return size_of_utf_string(String);
}
void* AllocatePool(UINTN AllocationSize)
{
return (void*)malloc((size_t)AllocationSize);
}
void* AllocateZeroPool(UINTN AllocationSize)
{
void* p = (void*)malloc((size_t)AllocationSize);
memset(p, 0, (size_t)AllocationSize);
return p;
}
void* ReallocatePool(UINTN OldSize, UINTN NewSize, void* OldBuffer)
{
(void)OldSize;
if ( !OldBuffer ) return AllocatePool(NewSize);
return (void*)realloc(OldBuffer, (size_t)NewSize);
}
void FreePool(const void* Buffer)
{
free((void*)Buffer);
}
void ZeroMem(void *Destination, UINTN Length)
{
memset(Destination, 0, (size_t)Length);
}
void SetMem(void *Destination, UINTN Length, char c)
{
memset(Destination, c, (size_t)Length);
}
void CopyMem(void *Destination, void *Source, UINTN Length)
{
memmove(Destination, Source, (size_t)Length);
}
CHAR16* EfiStrDuplicate (IN CONST CHAR16 *Src)
{
CHAR16* newS = (CHAR16*)malloc((wcslen_fixed(Src)+1)*sizeof(wchar_t));
memcpy(newS, Src, (wcslen_fixed(Src)+1)*sizeof(wchar_t));
return newS;
}
CHAR16* StrStr (IN CONST CHAR16 *String, IN CONST CHAR16 *SearchString)
{
return (CHAR16*)wcsstr_fixed(String, SearchString);
}
//UINTN AsciiStrLen(const char* String)
//{
// return (UINTN)strlen(String);
//}
//
//INTN AsciiStrCmp (const char *FirstString,const char *SecondString)
//{
// return (INTN)strcmp(FirstString, SecondString);
//}
//int StrCmp(const wchar_t* FirstString, const wchar_t* SecondString)
//{
//#if __WCHAR_MAX__ > 0xFFFFu || _MSC_VER
// int ret = wcscmp(FirstString, SecondString);
// return ret;
//#else
// // Looks like wcscmp doesn't work with Utf16, even if compiled with -fshort-wchar.
// // So conversion to Utf32 needed first.
//
// std::vector<char32_t> FirstStringUtf32;
// std::vector<char32_t> SecondStringUtf32;
//
// convert_utf16_to_utf32((const char16_t*)FirstString, StrLen(FirstString), &FirstStringUtf32);
// convert_utf16_to_utf32((const char16_t*)SecondString, StrLen(SecondString), &SecondStringUtf32);
//
// int ret = wcscmp((const wchar_t*)FirstStringUtf32.data(), (const wchar_t*)SecondStringUtf32.data());
// return ret;
//#endif
//}
//
//int StrnCmp(const wchar_t* FirstString, const wchar_t* SecondString, UINTN Length)
//{
//#if __WCHAR_MAX__ > 0xFFFFu
// return wcsncmp(FirstString, SecondString, Length);
//#else
//
//#ifdef _MSC_VER
// return wcsncmp(FirstString, SecondString, (size_t)Length);
//#else
// // Looks like wcscmp doesn't work with Utf16, even if compiled with -fshort-wchar.
// // So conversion to Utf32 needed first.
//
// std::vector<char32_t> FirstStringUtf32;
// std::vector<char32_t> SecondStringUtf32;
//
// convert_utf16_to_utf32((const char16_t*)FirstString, StrLen(FirstString), &FirstStringUtf32);
// convert_utf16_to_utf32((const char16_t*)SecondString, StrLen(FirstString), &SecondStringUtf32);
//
// int ret = wcsncmp((const wchar_t*)FirstStringUtf32.data(), (const wchar_t*)SecondStringUtf32.data(), Length);
////printf("wcsncmp=%d\n", ret);
// return ret;
//#endif
//#endif
//}