]> git.proxmox.com Git - mirror_edk2.git/blame - RedfishPkg/PrivateInclude/Library/RedfishCrtLib.h
MdePkg: Fix broken coding style in Acpi64.h
[mirror_edk2.git] / RedfishPkg / PrivateInclude / Library / RedfishCrtLib.h
CommitLineData
6e9233f9
AC
1/** @file\r
2 Redfish CRT wrapper functions.\r
3\r
4 Copyright (c) 2019, Intel Corporation. All rights reserved.<BR>\r
5 (C) Copyright 2020 Hewlett Packard Enterprise Development LP<BR>\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8\r
9**/\r
10\r
11#ifndef REDFISH_CRT_LIB_H_\r
12#define REDFISH_CRT_LIB_H_\r
13\r
14#include <Library/BaseLib.h>\r
15#include <Library/BaseMemoryLib.h>\r
16#include <Library/DebugLib.h>\r
17#include <Library/PrintLib.h>\r
18\r
19#define MAX_STRING_SIZE 0x10000000\r
20\r
21// Minimum value for an object of type long long int.\r
22#define LLONG_MIN MIN_INT64\r
23\r
24// Maximum value for an object of type long long int.\r
25#define LLONG_MAX MAX_INT64\r
26\r
27// We dont support double on edk2\r
28#define HUGE_VAL 0\r
29\r
30#if defined(MDE_CPU_X64) || defined(MDE_CPU_AARCH64) || defined(MDE_CPU_RISCV64)\r
31//\r
32// With GCC we would normally use SIXTY_FOUR_BIT_LONG, but MSVC needs\r
33// SIXTY_FOUR_BIT, because 'long' is 32-bit and only 'long long' is\r
34// 64-bit. Since using 'long long' works fine on GCC too, just do that.\r
35//\r
36#define SIXTY_FOUR_BIT\r
37#elif defined(MDE_CPU_IA32) || defined(MDE_CPU_ARM) || defined(MDE_CPU_EBC)\r
38#define THIRTY_TWO_BIT\r
39#endif\r
40\r
41//\r
42// Map all va_xxxx elements to VA_xxx defined in MdePkg/Include/Base.h\r
43//\r
44#if !defined(__CC_ARM) // if va_list is not already defined\r
45#define va_list VA_LIST\r
46#define va_arg VA_ARG\r
47#define va_start VA_START\r
48#define va_end VA_END\r
49#else // __CC_ARM\r
50#define va_start(Marker, Parameter) __va_start(Marker, Parameter)\r
51#define va_arg(Marker, TYPE) __va_arg(Marker, TYPE)\r
52#define va_end(Marker) ((void)0)\r
53#endif\r
54\r
55//\r
56// Definitions for global constants used by CRT library routines\r
57//\r
58#define INT_MAX MAX_INT32 /* Maximum (signed) int value */\r
59#define LONG_MAX 0X7FFFFFFFL /* max value for a long */\r
60#define LONG_MIN (-LONG_MAX-1) /* min value for a long */\r
61#define ULONG_MAX 0xFFFFFFFF /* Maximum unsigned long value */\r
62#define CHAR_BIT 8 /* Number of bits in a char */\r
63\r
64// Maximum value for an object of type unsigned long long int.\r
65#define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL // 2^64 - 1\r
66// Maximum value for an object of type unsigned char.\r
67#define UCHAR_MAX 255 // 2^8 - 1\r
68\r
69//\r
70// Basic types mapping\r
71//\r
72typedef UINTN size_t;\r
73typedef INTN ssize_t;\r
74typedef INT32 time_t;\r
75typedef UINT8 __uint8_t;\r
76typedef UINT8 sa_family_t;\r
77typedef UINT32 uid_t;\r
78typedef UINT32 gid_t;\r
79typedef INT32 int32_t;\r
80typedef UINT32 uint32_t;\r
81typedef UINT16 uint16_t;\r
82typedef UINT8 uint8_t;\r
83typedef enum {false, true} bool;\r
84\r
85//\r
86// File operations are not required for EFI building,\r
87// so FILE is mapped to VOID * to pass build\r
88//\r
89typedef VOID *FILE;\r
90\r
91/**\r
92 This is the Redfish version of CRT snprintf function, this function replaces "%s" to\r
93 "%a" before invoking AsciiSPrint(). That is becasue "%s" is unicode base on edk2\r
94 environment however "%s" is ascii code base on snprintf().\r
95 See definitions of AsciiSPrint() for the details.\r
96\r
97 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
98 ASCII string.\r
99 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
100 @param FormatString A Null-terminated ASCII format string.\r
101 @param ... Variable argument list whose contents are accessed based on the\r
102 format string specified by FormatString.\r
103\r
104 @return The number of ASCII characters in the produced output buffer not including the\r
105 Null-terminator. Zero means no string is produced or the error happens.\r
106\r
107**/\r
108UINTN\r
109EFIAPI\r
110RedfishAsciiSPrint (\r
111 OUT CHAR8 *StartOfBuffer,\r
112 IN UINTN BufferSize,\r
113 IN CONST CHAR8 *FormatString,\r
114 ...\r
115 );\r
116\r
117/**\r
118 This is the Redfish version of CRT vsnprintf function, this function replaces "%s" to\r
119 "%a" before invoking AsciiVSPrint(). That is because "%s" is unicode base on edk2\r
120 environment however "%s" is ascii code base on vsnprintf().\r
121 See definitions of AsciiVSPrint() for the details.\r
122\r
123 @param StartOfBuffer A pointer to the output buffer for the produced Null-terminated\r
124 ASCII string.\r
125 @param BufferSize The size, in bytes, of the output buffer specified by StartOfBuffer.\r
126 @param FormatString A Null-terminated ASCII format string.\r
127 @param Marker VA_LIST marker for the variable argument list.\r
128\r
129 @return The number of ASCII characters in the produced output buffer not including the\r
130 Null-terminator.\r
131\r
132**/\r
133UINTN\r
134EFIAPI\r
135RedfishAsciiVSPrint (\r
136 OUT CHAR8 *StartOfBuffer,\r
137 IN UINTN BufferSize,\r
138 IN CONST CHAR8 *FormatString,\r
139 IN VA_LIST Marker\r
140 );\r
141\r
142//\r
143// Global variables\r
144//\r
145extern int errno;\r
146extern FILE *stderr;\r
147\r
148//\r
149// Function prototypes of CRT Library routines\r
150//\r
151void *malloc (size_t);\r
152void *realloc (void *, size_t);\r
153void *calloc (size_t Num, size_t Size);\r
154void free (void *);\r
155void *memset (void *, int, size_t);\r
156int memcmp (const void *, const void *, size_t);\r
157int isdigit (int);\r
158int isspace (int);\r
159int tolower (int);\r
160int isupper (int);\r
161int isxdigit (int);\r
162int isalnum (int);\r
163void *memcpy (void *, const void *, size_t);\r
164void *memset (void *, int, size_t);\r
165void *memchr (const void *, int, size_t);\r
166int memcmp (const void *, const void *, size_t);\r
167void *memmove (void *, const void *, size_t);\r
168int strcmp (const char *, const char *);\r
169int strncmp (const char *, const char *, size_t);\r
170char *strcpy (char *, const char *);\r
171size_t strlen (const char *);\r
172char *strcat (char *, const char *);\r
173char *strchr (const char *, int);\r
174int strcasecmp (const char *, const char *);\r
175int strncasecmp (const char *, const char *, size_t);\r
176char *strncpy (char *, size_t, const char *, size_t);\r
177int strncmp (const char *, const char *, size_t);\r
178char *strrchr (const char *, int);\r
179unsigned long strtoul (const char *, char **, int);\r
180char * strstr (const char *s1 , const char *s2);\r
181long strtol (const char *, char **, int);\r
182char *strerror (int);\r
183size_t strspn (const char *, const char *);\r
184char * strdup (const char *str);\r
185char * strpbrk (const char *s1, const char *s2);\r
186unsigned long long strtoull(const char * nptr, char ** endptr, int base);\r
187long long strtoll (const char * nptr, char ** endptr, int base);\r
188long strtol (const char * nptr, char ** endptr, int base);\r
189double strtod (const char * __restrict nptr, char ** __restrict endptr);\r
190size_t strcspn (const char *, const char *);\r
191int printf (const char *, ...);\r
192int sscanf (const char *, const char *, ...);\r
193FILE *fopen (const char *, const char *);\r
194size_t fread (void *, size_t, size_t, FILE *);\r
195size_t fwrite (const void *, size_t, size_t, FILE *);\r
196int fclose (FILE *);\r
197int fprintf (FILE *, const char *, ...);\r
198int fgetc (FILE * _File);\r
199uid_t getuid (void);\r
200uid_t geteuid (void);\r
201gid_t getgid (void);\r
202gid_t getegid (void);\r
203void qsort (void *, size_t, size_t, int (*)(const void *, const void *));\r
204char *getenv (const char *);\r
205#if defined(__GNUC__) && (__GNUC__ >= 2)\r
206void abort (void) __attribute__((__noreturn__));\r
207#else\r
208void abort (void);\r
209#endif\r
210int toupper (int);\r
211int Digit2Val (int);\r
212time_t time (time_t *);\r
213\r
214//\r
215// Macros that directly map functions to BaseLib, BaseMemoryLib, and DebugLib functions\r
216//\r
217#define strcmp AsciiStrCmp\r
218#define memcpy(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r
219#define memset(dest,ch,count) SetMem(dest,(UINTN)(count),(UINT8)(ch))\r
220#define memchr(buf,ch,count) ScanMem8(buf,(UINTN)(count),(UINT8)ch)\r
221#define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count)))\r
222#define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count))\r
223#define strlen(str) (size_t)(AsciiStrnLenS(str,MAX_STRING_SIZE))\r
224#define strcpy(strDest,strSource) AsciiStrCpyS(strDest,(strlen(strSource)+1),strSource)\r
225#define strncpy(strDest,strSource,count) AsciiStrnCpyS(strDest,(UINTN)count,strSource,(UINTN)count)\r
226#define strncpys(strDest, DestLen, strSource,count) AsciiStrnCpyS(strDest,DestLen,strSource,(UINTN)count)\r
227#define strcat(strDest,strSource) AsciiStrCatS(strDest,(strlen(strSource)+strlen(strDest)+1),strSource)\r
228#define strchr(str,ch) ScanMem8((VOID *)(str),AsciiStrSize(str),(UINT8)ch)\r
229#define strcasecmp(str1,str2) (int)AsciiStriCmp(str1,str2)\r
230#define strstr(s1,s2) AsciiStrStr(s1,s2)\r
231#define snprintf(buf,len,...) RedfishAsciiSPrint(buf,len,__VA_ARGS__)\r
232#define vsnprintf(buf,len,format,marker) RedfishAsciiVSPrint((buf),(len),(format),(marker))\r
233#define assert(expression) ASSERT(expression)\r
234#define offsetof(type,member) OFFSET_OF(type,member)\r
235\r
236#define EOF (-1)\r
237\r
238extern int errno;\r
239\r
240#define ERANGE 34 /* 34 Result too large */\r
241\r
242#endif\r