VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/RedfishPkg/Include/Library/RedfishCrtLib.h@ 105668

最後變更 在這個檔案從105668是 99404,由 vboxsync 提交於 2 年 前

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

  • 屬性 svn:eol-style 設為 native
檔案大小: 9.7 KB
 
1/** @file
2 Redfish CRT wrapper functions.
3
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2021 Hewlett Packard Enterprise Development LP<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9**/
10
11#ifndef REDFISH_CRT_LIB_H_
12#define REDFISH_CRT_LIB_H_
13
14#include <Library/BaseLib.h>
15#include <Library/BaseMemoryLib.h>
16#include <Library/DebugLib.h>
17#include <Library/PrintLib.h>
18
19#define MAX_STRING_SIZE 0x10000000
20
21// Minimum value for an object of type long long int.
22#define LLONG_MIN MIN_INT64
23
24// Maximum value for an object of type long long int.
25#define LLONG_MAX MAX_INT64
26
27// We dont support double on edk2
28#define HUGE_VAL 0
29
30#if defined (MDE_CPU_X64) || defined (MDE_CPU_AARCH64) || defined (MDE_CPU_RISCV64)
31//
32// With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs
33// SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is
34// 64-bit. Since using 'long long' works fine on GCC too, just do that.
35//
36#define SIXTY_FOUR_BIT
37#elif defined (MDE_CPU_IA32) || defined (MDE_CPU_ARM) || defined (MDE_CPU_EBC)
38#define THIRTY_TWO_BIT
39#endif
40
41//
42// Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h
43//
44#if !defined (__CC_ARM) // if va_list is not already defined
45#define va_list VA_LIST
46#define va_arg VA_ARG
47#define va_start VA_START
48#define va_end VA_END
49#else // __CC_ARM
50#define va_start(Marker, Parameter) __va_start(Marker, Parameter)
51#define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)
52#define va_end(Marker) ((void)0)
53#endif
54
55//
56// Definitions for global constants used by CRT library routines
57//
58#define INT_MAX MAX_INT32 /* Maximum (signed) int value */
59#define LONG_MAX 0X7FFFFFFFL /* max value for a long */
60#define LONG_MIN (-LONG_MAX-1) /* min value for a long */
61#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */
62#define CHAR_BIT 8 /* Number of bits in a char */
63
64// Maximum value for an object of type unsigned long long int.
65#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL // 2^64 - 1
66// Maximum value for an object of type unsigned char.
67#define UCHAR_MAX 255 // 2^8 - 1
68
69//
70// Basic types mapping
71//
72typedef UINTN size_t;
73typedef INTN ssize_t;
74typedef INT32 time_t;
75typedef UINT8 __uint8_t;
76typedef UINT8 sa_family_t;
77typedef UINT32 uid_t;
78typedef UINT32 gid_t;
79typedef INT32 int32_t;
80typedef UINT32 uint32_t;
81typedef UINT16 uint16_t;
82typedef UINT8 uint8_t;
83typedef enum {
84 false, true
85} bool;
86
87//
88// File operations are not required for EFI building,
89// so FILE is mapped to VOID * to pass build
90//
91typedef VOID *FILE;
92
93/**
94 This is the Redfish version of CRT snprintf function, this function replaces "%s" to
95 "%a" before invoking AsciiSPrint(). That is becasue "%s" is unicode base on edk2
96 environment however "%s" is ascii code base on snprintf().
97 See definitions of AsciiSPrint() for the details.
98
99 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
100 ASCII string.
101 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
102 @param FormatString A Null-terminated ASCII format string.
103 @param ... Variable argument list whose contents are accessed based on the
104 format string specified by FormatString.
105
106 @return The number of ASCII characters in the produced output buffer not including the
107 Null-terminator. Zero means no string is produced or the error happens.
108
109**/
110UINTN
111EFIAPI
112RedfishAsciiSPrint (
113 OUT CHAR8 *StartOfBuffer,
114 IN UINTN BufferSize,
115 IN CONST CHAR8 *FormatString,
116 ...
117 );
118
119/**
120 This is the Redfish version of CRT vsnprintf function, this function replaces "%s" to
121 "%a" before invoking AsciiVSPrint(). That is because "%s" is unicode base on edk2
122 environment however "%s" is ascii code base on vsnprintf().
123 See definitions of AsciiVSPrint() for the details.
124
125 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated
126 ASCII string.
127 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.
128 @param FormatString A Null-terminated ASCII format string.
129 @param Marker VA_LIST marker for the variable argument list.
130
131 @return The number of ASCII characters in the produced output buffer not including the
132 Null-terminator.
133
134**/
135UINTN
136EFIAPI
137RedfishAsciiVSPrint (
138 OUT CHAR8 *StartOfBuffer,
139 IN UINTN BufferSize,
140 IN CONST CHAR8 *FormatString,
141 IN VA_LIST Marker
142 );
143
144//
145// Global variables
146//
147extern int errno;
148extern FILE *stderr;
149
150//
151// Function prototypes of CRT Library routines
152//
153void *
154malloc (
155 size_t
156 );
157
158void *
159realloc (
160 void *,
161 size_t
162 );
163
164void *
165calloc (
166 size_t Num,
167 size_t Size
168 );
169
170void
171free (
172 void *
173 );
174
175void *
176memset (
177 void *,
178 int,
179 size_t
180 );
181
182int
183memcmp (
184 const void *,
185 const void *,
186 size_t
187 );
188
189int
190isdigit (
191 int
192 );
193
194int
195isspace (
196 int
197 );
198
199int
200tolower (
201 int
202 );
203
204int
205isupper (
206 int
207 );
208
209int
210isxdigit (
211 int
212 );
213
214int
215isalnum (
216 int
217 );
218
219void *
220memcpy (
221 void *,
222 const void *,
223 size_t
224 );
225
226void *
227memset (
228 void *,
229 int,
230 size_t
231 );
232
233void *
234memchr (
235 const void *,
236 int,
237 size_t
238 );
239
240int
241memcmp (
242 const void *,
243 const void *,
244 size_t
245 );
246
247void *
248memmove (
249 void *,
250 const void *,
251 size_t
252 );
253
254int
255strcmp (
256 const char *,
257 const char *
258 );
259
260int
261strncmp (
262 const char *,
263 const char *,
264 size_t
265 );
266
267char *
268strcpy (
269 char *,
270 const char *
271 );
272
273size_t
274strlen (
275 const char *
276 );
277
278char *
279strcat (
280 char *,
281 const char *
282 );
283
284char *
285strchr (
286 const char *,
287 int
288 );
289
290int
291strcasecmp (
292 const char *,
293 const char *
294 );
295
296int
297strncasecmp (
298 const char *,
299 const char *,
300 size_t
301 );
302
303char *
304strncpy (
305 char *,
306 size_t,
307 const char *,
308 size_t
309 );
310
311int
312strncmp (
313 const char *,
314 const char *,
315 size_t
316 );
317
318char *
319strrchr (
320 const char *,
321 int
322 );
323
324unsigned long
325strtoul (
326 const char *,
327 char **,
328 int
329 );
330
331char *
332strstr (
333 const char *s1,
334 const char *s2
335 );
336
337long
338strtol (
339 const char *,
340 char **,
341 int
342 );
343
344char *
345strerror (
346 int
347 );
348
349size_t
350strspn (
351 const char *,
352 const char *
353 );
354
355char *
356strdup (
357 const char *str
358 );
359
360char *
361strpbrk (
362 const char *s1,
363 const char *s2
364 );
365
366unsigned long long
367strtoull (
368 const char *nptr,
369 char **endptr,
370 int base
371 );
372
373long long
374strtoll (
375 const char *nptr,
376 char **endptr,
377 int base
378 );
379
380long
381strtol (
382 const char *nptr,
383 char **endptr,
384 int base
385 );
386
387double
388strtod (
389 const char *__restrict nptr,
390 char **__restrict endptr
391 );
392
393size_t
394strcspn (
395 const char *,
396 const char *
397 );
398
399int
400printf (
401 const char *,
402 ...
403 );
404
405int
406sscanf (
407 const char *,
408 const char *,
409 ...
410 );
411
412FILE *
413fopen (
414 const char *,
415 const char *
416 );
417
418size_t
419fread (
420 void *,
421 size_t,
422 size_t,
423 FILE *
424 );
425
426size_t
427fwrite (
428 const void *,
429 size_t,
430 size_t,
431 FILE *
432 );
433
434int
435fclose (
436 FILE *
437 );
438
439int
440fprintf (
441 FILE *,
442 const char *,
443 ...
444 );
445
446int
447fgetc (
448 FILE *_File
449 );
450
451uid_t
452getuid (
453 void
454 );
455
456uid_t
457geteuid (
458 void
459 );
460
461gid_t
462getgid (
463 void
464 );
465
466gid_t
467getegid (
468 void
469 );
470
471void
472qsort (
473 void *,
474 size_t,
475 size_t,
476 int (*)(const void *, const void *)
477 );
478
479char *
480getenv (
481 const char *
482 );
483
484#if defined (__GNUC__) && (__GNUC__ >= 2)
485void
486abort (
487 void
488 ) __attribute__ ((__noreturn__));
489
490#else
491void
492abort (
493 void
494 );
495
496#endif
497int
498toupper (
499 int
500 );
501
502int
503Digit2Val (
504 int
505 );
506
507time_t
508time (
509 time_t *
510 );
511
512//
513// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
514//
515#define strcmp AsciiStrCmp
516#define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count))
517#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
518#define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
519#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
520#define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))
521#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
522#define strcpy(strDest, strSource) AsciiStrCpyS(strDest,(strlen(strSource)+1),strSource)
523#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,(UINTN)count,strSource,(UINTN)count)
524#define strncpys(strDest, DestLen, strSource, count) AsciiStrnCpyS(strDest,DestLen,strSource,(UINTN)count)
525#define strcat(strDest, strSource) AsciiStrCatS(strDest,(strlen(strSource)+strlen(strDest)+1),strSource)
526#define strchr(str, ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
527#define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2)
528#define strstr(s1, s2) AsciiStrStr(s1,s2)
529#define snprintf(buf, len, ...) RedfishAsciiSPrint(buf,len,__VA_ARGS__)
530#define vsnprintf(buf, len, format, marker) RedfishAsciiVSPrint((buf),(len),(format),(marker))
531#define assert(expression) ASSERT(expression)
532#define offsetof(type, member) OFFSET_OF(type,member)
533
534#define EOF (-1)
535
536extern int errno;
537
538#define ERANGE 34 /* 34 Result too large */
539
540#endif
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette