TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishCrtLib.h
Go to the documentation of this file.
1
11#ifndef REDFISH_CRT_LIB_H_
12#define REDFISH_CRT_LIB_H_
13
14#include <Library/BaseLib.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 INT32 int32_t;
76typedef UINT32 uint32_t;
77typedef UINT16 uint16_t;
78typedef UINT8 uint8_t;
79typedef BOOLEAN bool;
80
81#define true (1 == 1)
82#define false (1 == 0)
83
84//
85// File operations are not required for EFI building,
86// so FILE is mapped to VOID * to pass build
87//
88typedef VOID *FILE;
89
107UINTN
108EFIAPI
110 OUT CHAR8 *StartOfBuffer,
111 IN UINTN BufferSize,
112 IN CONST CHAR8 *FormatString,
113 ...
114 );
115
132UINTN
133EFIAPI
135 OUT CHAR8 *StartOfBuffer,
136 IN UINTN BufferSize,
137 IN CONST CHAR8 *FormatString,
138 IN VA_LIST Marker
139 );
140
141//
142// Global variables
143//
144extern int errno;
145extern FILE *stderr;
146
147//
148// Function prototypes of CRT Library routines
149//
150void *
151malloc (
152 size_t
153 );
154
155void *
156realloc (
157 void *,
158 size_t
159 );
160
161void *
162calloc (
163 size_t Num,
164 size_t Size
165 );
166
167void
168free (
169 void *
170 );
171
172int
173isdigit (
174 int
175 );
176
177int
178isspace (
179 int
180 );
181
182int
183tolower (
184 int
185 );
186
187int
188isupper (
189 int
190 );
191
192int
193isxdigit (
194 int
195 );
196
197int
198isalnum (
199 int
200 );
201
202int
203strncmp (
204 const char *,
205 const char *,
206 size_t
207 );
208
209int
210strncasecmp (
211 const char *,
212 const char *,
213 size_t
214 );
215
216char *
217strrchr (
218 const char *,
219 int
220 );
221
222unsigned long
223strtoul (
224 const char *,
225 char **,
226 int
227 );
228
229long
230strtol (
231 const char *,
232 char **,
233 int
234 );
235
236char *
237strerror (
238 int
239 );
240
241size_t
242strspn (
243 const char *,
244 const char *
245 );
246
247char *
248strdup (
249 const char *str
250 );
251
252char *
253strpbrk (
254 const char *s1,
255 const char *s2
256 );
257
258unsigned long long
259strtoull (
260 const char *nptr,
261 char **endptr,
262 int base
263 );
264
265long long
266strtoll (
267 const char *nptr,
268 char **endptr,
269 int base
270 );
271
272long
273strtol (
274 const char *nptr,
275 char **endptr,
276 int base
277 );
278
279double
280strtod (
281 const char *__restrict nptr,
282 char **__restrict endptr
283 );
284
285size_t
286strcspn (
287 const char *,
288 const char *
289 );
290
291int
292printf (
293 const char *,
294 ...
295 );
296
297int
298sscanf (
299 const char *,
300 const char *,
301 ...
302 );
303
304FILE *
305fopen (
306 const char *,
307 const char *
308 );
309
310size_t
311fread (
312 void *,
313 size_t,
314 size_t,
315 FILE *
316 );
317
318size_t
319fwrite (
320 const void *,
321 size_t,
322 size_t,
323 FILE *
324 );
325
326int
327fclose (
328 FILE *
329 );
330
331int
332fprintf (
333 FILE *,
334 const char *,
335 ...
336 );
337
338int
339fgetc (
340 FILE *_File
341 );
342
343void
344qsort (
345 void *,
346 size_t,
347 size_t,
348 int (*)(const void *, const void *)
349 );
350
351char *
352getenv (
353 const char *
354 );
355
356#if defined (__GNUC__) && (__GNUC__ >= 2)
357void
358abort (
359 void
360 ) __attribute__ ((__noreturn__));
361
362#else
363void
364abort (
365 void
366 );
367
368#endif
369int
370toupper (
371 int
372 );
373
374int
375Digit2Val (
376 int
377 );
378
379time_t
380time (
381 time_t *
382 );
383
384//
385// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions
386//
387#define strcmp AsciiStrCmp
388#define memcpy(dest, source, count) CopyMem(dest,source,(UINTN)(count))
389#define memset(dest, ch, count) SetMem(dest,(UINTN)(count),(UINT8)(ch))
390#define memchr(buf, ch, count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)
391#define memcmp(buf1, buf2, count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))
392#define memmove(dest, source, count) CopyMem(dest,source,(UINTN)(count))
393#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))
394#define strcpy(strDest, strSource) AsciiStrCpyS(strDest,(strlen(strSource)+1),strSource)
395#define strncpy(strDest, strSource, count) AsciiStrnCpyS(strDest,(UINTN)count,strSource,(UINTN)count)
396#define strncpys(strDest, DestLen, strSource, count) AsciiStrnCpyS(strDest,DestLen,strSource,(UINTN)count)
397#define strcat(strDest, strSource) AsciiStrCatS(strDest,(strlen(strSource)+strlen(strDest)+1),strSource)
398#define strchr(str, ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)
399#define strcasecmp(str1, str2) (int)AsciiStriCmp(str1,str2)
400#define strstr(s1, s2) AsciiStrStr(s1,s2)
401#define snprintf(buf, len, ...) RedfishAsciiSPrint(buf,len,__VA_ARGS__)
402#define vsnprintf(buf, len, format, marker) RedfishAsciiVSPrint((buf),(len),(format),(marker))
403#define assert(expression) ASSERT(expression)
404#define offsetof(type, member) OFFSET_OF(type,member)
405
406#define EOF (-1)
407
408extern int errno;
409
410#define ERANGE 34 /* 34 Result too large */
411
412#endif
UINT64 UINTN
INT64 INTN
#define CONST
Definition: Base.h:259
CHAR8 * VA_LIST
Definition: Base.h:643
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
long strtol(const char *, char **, int)
Definition: CrtWrapper.c:400
int Digit2Val(int)
char * strerror(int)
Definition: CrtWrapper.c:195
double strtod(const char *__restrict nptr, char **__restrict endptr)
char * strpbrk(const char *s1, const char *s2)
void qsort(void *, size_t, size_t, int(*)(const void *, const void *))
Definition: CrtWrapper.c:447
int fclose(FILE *)
Definition: CrtWrapper.c:565
int isalnum(int)
Definition: CrtWrapper.c:370
int isspace(int)
Definition: CrtWrapper.c:358
time_t time(time_t *)
size_t fread(void *, size_t, size_t, FILE *)
Definition: CrtWrapper.c:582
UINTN EFIAPI RedfishAsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
int fgetc(FILE *_File)
char * strdup(const char *str)
int errno
UINTN EFIAPI RedfishAsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
FILE * fopen(const char *, const char *)
Definition: CrtWrapper.c:573
unsigned long long strtoull(const char *nptr, char **endptr, int base)
size_t fwrite(const void *, size_t, size_t, FILE *)
Definition: CrtWrapper.c:513
long long strtoll(const char *nptr, char **endptr, int base)
unsigned long long UINT64 __attribute__((aligned(8)))
Definition: ProcessorBind.h:28