BaseTools: Add DevicePath support for PCD values
[mirror_edk2.git] / BaseTools / Source / C / Common / CommonLib.h
CommitLineData
30fdf114 1/** @file\r
97fa0ee9 2Common library assistance routines.\r
30fdf114 3\r
7dbc50bd 4Copyright (c) 2004 - 2017, Intel Corporation. All rights reserved.<BR>\r
40d841f6 5This program and the accompanying materials\r
30fdf114
LG
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
30fdf114
LG
13**/\r
14\r
15#ifndef _EFI_COMMON_LIB_H\r
16#define _EFI_COMMON_LIB_H\r
17\r
18#include <Common/UefiBaseTypes.h>\r
b36d134f 19#include <Common/BuildVersion.h>\r
7dbc50bd 20#include <assert.h>\r
30fdf114 21#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination\r
1be2ed90
HC
22\r
23#define MAX_LONG_FILE_PATH 500\r
24\r
7dbc50bd
YZ
25#define MAX_UINTN MAX_ADDRESS\r
26#define MAX_UINT64 ((UINT64)0xFFFFFFFFFFFFFFFFULL)\r
27#define MAX_UINT16 ((UINT16)0xFFFF)\r
28#define MAX_UINT8 ((UINT8)0xFF)\r
29#define ARRAY_SIZE(Array) (sizeof (Array) / sizeof ((Array)[0]))\r
30#define ASCII_RSIZE_MAX 1000000\r
31#ifndef RSIZE_MAX\r
32#define RSIZE_MAX 1000000\r
33#endif\r
34\r
35#define IS_COMMA(a) ((a) == L',')\r
36#define IS_HYPHEN(a) ((a) == L'-')\r
37#define IS_DOT(a) ((a) == L'.')\r
38#define IS_LEFT_PARENTH(a) ((a) == L'(')\r
39#define IS_RIGHT_PARENTH(a) ((a) == L')')\r
40#define IS_SLASH(a) ((a) == L'/')\r
41#define IS_NULL(a) ((a) == L'\0')\r
42\r
43#define ASSERT(x) assert(x)\r
44\r
1be2ed90
HC
45#ifdef __cplusplus\r
46extern "C" {\r
47#endif\r
97fa0ee9 48\r
30fdf114
LG
49//\r
50// Function declarations\r
51//\r
52VOID\r
53PeiZeroMem (\r
54 IN VOID *Buffer,\r
55 IN UINTN Size\r
56 )\r
57;\r
58\r
59VOID\r
60PeiCopyMem (\r
61 IN VOID *Destination,\r
62 IN VOID *Source,\r
63 IN UINTN Length\r
64 )\r
65;\r
66\r
67VOID\r
68ZeroMem (\r
69 IN VOID *Buffer,\r
70 IN UINTN Size\r
71 )\r
72;\r
73\r
74VOID\r
75CopyMem (\r
76 IN VOID *Destination,\r
77 IN VOID *Source,\r
78 IN UINTN Length\r
79 )\r
80;\r
81\r
82INTN\r
83CompareGuid (\r
84 IN EFI_GUID *Guid1,\r
85 IN EFI_GUID *Guid2\r
86 )\r
87;\r
88\r
89EFI_STATUS\r
90GetFileImage (\r
91 IN CHAR8 *InputFileName,\r
92 OUT CHAR8 **InputFileImage,\r
93 OUT UINT32 *BytesRead\r
94 )\r
95;\r
96\r
97EFI_STATUS\r
98PutFileImage (\r
99 IN CHAR8 *OutputFileName,\r
100 IN CHAR8 *OutputFileImage,\r
101 IN UINT32 BytesToWrite\r
102 )\r
103;\r
104/*++\r
105\r
106Routine Description:\r
107\r
108 This function opens a file and writes OutputFileImage into the file.\r
109\r
110Arguments:\r
111\r
112 OutputFileName The name of the file to write.\r
113 OutputFileImage A pointer to the memory buffer.\r
114 BytesToWrite The size of the memory buffer.\r
115\r
116Returns:\r
117\r
118 EFI_SUCCESS The function completed successfully.\r
119 EFI_INVALID_PARAMETER One of the input parameters was invalid.\r
120 EFI_ABORTED An error occurred.\r
121 EFI_OUT_OF_RESOURCES No resource to complete operations.\r
122\r
123**/\r
124\r
125UINT8\r
126CalculateChecksum8 (\r
127 IN UINT8 *Buffer,\r
128 IN UINTN Size\r
129 )\r
130;\r
131\r
132UINT8\r
133CalculateSum8 (\r
134 IN UINT8 *Buffer,\r
135 IN UINTN Size\r
136 )\r
137;\r
138\r
139UINT16\r
140CalculateChecksum16 (\r
141 IN UINT16 *Buffer,\r
142 IN UINTN Size\r
143 )\r
144;\r
145\r
146UINT16\r
147CalculateSum16 (\r
148 IN UINT16 *Buffer,\r
149 IN UINTN Size\r
150 )\r
151;\r
152\r
153EFI_STATUS\r
154PrintGuid (\r
155 IN EFI_GUID *Guid\r
156 )\r
157;\r
158\r
159#define PRINTED_GUID_BUFFER_SIZE 37 // including null-termination\r
160EFI_STATUS\r
161PrintGuidToBuffer (\r
162 IN EFI_GUID *Guid,\r
163 IN OUT UINT8 *Buffer,\r
164 IN UINT32 BufferLen,\r
165 IN BOOLEAN Uppercase\r
166 )\r
167;\r
168\r
1be2ed90
HC
169CHAR8 *\r
170LongFilePath (\r
171 IN CHAR8 *FileName\r
172);\r
7dbc50bd
YZ
173\r
174UINTN\r
175StrLen (\r
176 CONST CHAR16 *String\r
177 );\r
178\r
179VOID *\r
180AllocateCopyPool (\r
181 UINTN AllocationSize,\r
182 CONST VOID *Buffer\r
183 );\r
184\r
185INTN\r
186StrnCmp (\r
187 CONST CHAR16 *FirstString,\r
188 CONST CHAR16 *SecondString,\r
189 UINTN Length\r
190 );\r
191\r
192RETURN_STATUS\r
193StrToGuid (\r
194 CONST CHAR16 *String,\r
195 EFI_GUID *Guid\r
196 );\r
197\r
198RETURN_STATUS\r
199StrHexToBytes (\r
200 CONST CHAR16 *String,\r
201 UINTN Length,\r
202 UINT8 *Buffer,\r
203 UINTN MaxBufferSize\r
204 );\r
205\r
206UINTN\r
207InternalHexCharToUintn (\r
208 CHAR16 Char\r
209 );\r
210\r
211VOID *\r
212InternalAllocateCopyPool (\r
213 UINTN AllocationSize,\r
214 CONST VOID *Buffer\r
215 );\r
216\r
217BOOLEAN\r
218InternalIsDecimalDigitCharacter (\r
219 CHAR16 Char\r
220 );\r
221\r
222UINT32\r
223SwapBytes32 (\r
224 UINT32 Value\r
225 );\r
226\r
227UINT16\r
228SwapBytes16 (\r
229 UINT16 Value\r
230 );\r
231\r
232EFI_GUID *\r
233CopyGuid (\r
234 EFI_GUID *DestinationGuid,\r
235 CONST EFI_GUID *SourceGuid\r
236 );\r
237\r
238UINT64\r
239WriteUnaligned64 (\r
240 UINT64 *Buffer,\r
241 UINT64 Value\r
242 );\r
243\r
244UINT64\r
245ReadUnaligned64 (\r
246 CONST UINT64 *Buffer\r
247 );\r
248\r
249UINTN\r
250StrSize (\r
251 CONST CHAR16 *String\r
252 );\r
253\r
254UINTN\r
255StrHexToUintn (\r
256 CONST CHAR16 *String\r
257 );\r
258\r
259UINTN\r
260StrDecimalToUintn (\r
261 CONST CHAR16 *String\r
262 );\r
263\r
264UINT64\r
265StrHexToUint64 (\r
266 CONST CHAR16 *String\r
267 );\r
268\r
269UINT64\r
270StrDecimalToUint64 (\r
271 CONST CHAR16 *String\r
272 );\r
273\r
274RETURN_STATUS\r
275StrHexToUint64S (\r
276 CONST CHAR16 *String,\r
277 CHAR16 **EndPointer,\r
278 UINT64 *Data\r
279 );\r
280\r
281RETURN_STATUS\r
282StrHexToUintnS (\r
283 CONST CHAR16 *String,\r
284 CHAR16 **EndPointer, OPTIONAL\r
285 UINTN *Data\r
286 );\r
287\r
288RETURN_STATUS\r
289StrDecimalToUint64S (\r
290 CONST CHAR16 *String,\r
291 CHAR16 **EndPointer, OPTIONAL\r
292 UINT64 *Data\r
293 );\r
294\r
295RETURN_STATUS\r
296StrDecimalToUintnS (\r
297 CONST CHAR16 *String,\r
298 CHAR16 **EndPointer, OPTIONAL\r
299 UINTN *Data\r
300 );\r
301\r
302VOID *\r
303ReallocatePool (\r
304 UINTN OldSize,\r
305 UINTN NewSize,\r
306 VOID *OldBuffer OPTIONAL\r
307 );\r
308\r
309VOID *\r
310InternalReallocatePool (\r
311 UINTN OldSize,\r
312 UINTN NewSize,\r
313 VOID *OldBuffer OPTIONAL\r
314 );\r
315\r
316VOID *\r
317InternalAllocateZeroPool (\r
318 UINTN AllocationSize\r
319 ) ;\r
320\r
321VOID *\r
322InternalAllocatePool (\r
323 UINTN AllocationSize\r
324 );\r
325\r
326UINTN\r
327StrnLenS (\r
328 CONST CHAR16 *String,\r
329 UINTN MaxSize\r
330 );\r
331\r
332CHAR16\r
333InternalCharToUpper (\r
334 CHAR16 Char\r
335 );\r
336\r
337INTN\r
338StrCmp (\r
339 CONST CHAR16 *FirstString,\r
340 CONST CHAR16 *SecondString\r
341 );\r
342\r
343UINT64\r
344SwapBytes64 (\r
345 UINT64 Value\r
346 );\r
347\r
348UINT64\r
349InternalMathSwapBytes64 (\r
350 UINT64 Operand\r
351 );\r
352\r
353RETURN_STATUS\r
354StrToIpv4Address (\r
355 CONST CHAR16 *String,\r
356 CHAR16 **EndPointer,\r
357 EFI_IPv4_ADDRESS *Address,\r
358 UINT8 *PrefixLength\r
359 );\r
360\r
361RETURN_STATUS\r
362StrToIpv6Address (\r
363 CONST CHAR16 *String,\r
364 CHAR16 **EndPointer,\r
365 EFI_IPv6_ADDRESS *Address,\r
366 UINT8 *PrefixLength\r
367 );\r
368\r
369RETURN_STATUS\r
370StrCpyS (\r
371 CHAR16 *Destination,\r
372 UINTN DestMax,\r
373 CONST CHAR16 *Source\r
374 );\r
375\r
376RETURN_STATUS\r
377UnicodeStrToAsciiStrS (\r
378 CONST CHAR16 *Source,\r
379 CHAR8 *Destination,\r
380 UINTN DestMax\r
381 );\r
382VOID *\r
383AllocatePool (\r
384 UINTN AllocationSize\r
385 );\r
386\r
387UINT16\r
388WriteUnaligned16 (\r
389 UINT16 *Buffer,\r
390 UINT16 Value\r
391 );\r
392\r
393UINT16\r
394ReadUnaligned16 (\r
395 CONST UINT16 *Buffer\r
396 );\r
397\r
398VOID *\r
399AllocateZeroPool (\r
400 UINTN AllocationSize\r
401 );\r
402\r
403BOOLEAN\r
404InternalIsHexaDecimalDigitCharacter (\r
405 CHAR16 Char\r
406 );\r
407\r
408BOOLEAN\r
409InternalSafeStringIsOverlap (\r
410 IN VOID *Base1,\r
411 IN UINTN Size1,\r
412 IN VOID *Base2,\r
413 IN UINTN Size2\r
414 );\r
415\r
416BOOLEAN\r
417InternalSafeStringNoStrOverlap (\r
418 IN CHAR16 *Str1,\r
419 IN UINTN Size1,\r
420 IN CHAR16 *Str2,\r
421 IN UINTN Size2\r
422 );\r
423\r
424BOOLEAN\r
425IsHexStr (\r
426 CHAR16 *Str\r
427 );\r
428\r
429UINTN\r
430Strtoi (\r
431 CHAR16 *Str\r
432 );\r
433\r
434VOID\r
435Strtoi64 (\r
436 CHAR16 *Str,\r
437 UINT64 *Data\r
438 );\r
439\r
440VOID\r
441StrToAscii (\r
442 CHAR16 *Str,\r
443 CHAR8 **AsciiStr\r
444 );\r
445\r
446CHAR16 *\r
447SplitStr (\r
448 CHAR16 **List,\r
449 CHAR16 Separator\r
450 );\r
451\r
1be2ed90
HC
452/*++\r
453\r
454Routine Description:\r
455 Convert FileName to the long file path, which can support larger than 260 length. \r
456\r
457Arguments:\r
458 FileName - FileName. \r
459\r
460Returns:\r
461 LongFilePath A pointer to the converted long file path.\r
462 \r
463--*/\r
464\r
465#ifdef __cplusplus\r
466}\r
467#endif\r
468\r
30fdf114
LG
469#ifdef __GNUC__\r
470#include <stdio.h>\r
471#include <sys/stat.h>\r
472#define stricmp strcasecmp\r
473#define _stricmp strcasecmp\r
474#define strnicmp strncasecmp\r
475#define strcmpi strcasecmp\r
476size_t _filelength(int fd);\r
477#ifndef __CYGWIN__\r
478char *strlwr(char *s);\r
479#endif\r
480#endif\r
481\r
482//\r
483// On windows, mkdir only has one parameter.\r
484// On unix, it has two parameters\r
485//\r
486#if defined(__GNUC__)\r
487#define mkdir(dir, perm) mkdir(dir, perm)\r
488#else\r
489#define mkdir(dir, perm) mkdir(dir)\r
490#endif\r
491\r
492#endif\r