19char errnum_message[] =
"We don't support to map errnum to the error message on edk2 Redfish\n";
36 return (((
'0' <= (c)) && ((c) <=
'9')) ||
37 ((
'a' <= (c)) && ((c) <=
'z')) ||
38 ((
'A' <= (c)) && ((c) <=
'Z')));
54 return (((
'0' <= (c)) && ((c) <=
'9')) ||
55 (c ==
'e') || (c ==
'E') ||
56 (c ==
'+') || (c ==
'-') ||
73 return ((c) ==
' ') || ((c) ==
'\t') || ((c) ==
'\r') || ((c) ==
'\n') || ((c) ==
'\v') || ((c) ==
'\f');
117 len = strlen (str) + 1;
118 if ((copy = malloc (len)) ==
NULL) {
122 memcpy (copy, str, len);
143 if ((c >=
'a') && (c <=
'z')) {
160 if (((c >=
'a') && (c <=
'z')) || ((c >=
'A') && (c <=
'Z'))) {
187 long long Result = 0;
190 BOOLEAN Negative =
FALSE;
194 if ((base < 0) || (base == 1) || (base > 36)) {
195 if (endptr !=
NULL) {
211 }
else if (*nptr ==
'-') {
218 if (
toupper (nptr[1]) ==
'X') {
220 if ((base == 0) || (base == 16)) {
226 if ((base == 0) || (base == 8)) {
239 for ( ; *nptr ==
'0'; ++nptr) {
248 Result =
MultS64x64 (Result, base) + (
long long int)temp;
249 if ( Result <= Previous) {
270 if (endptr !=
NULL) {
271 *endptr = (
char *)pEnd;
342 BOOLEAN Negative =
FALSE;
346 if ((base < 0) || (base == 1) || (base > 36)) {
347 if (endptr !=
NULL) {
363 }
else if (*nptr ==
'-') {
370 if (
toupper (nptr[1]) ==
'X') {
372 if ((base == 0) || (base == 16)) {
378 if ((base == 0) || (base == 8)) {
391 for ( ; *nptr ==
'0'; ++nptr) {
400 Result = (Result * base) + (
long int)temp;
401 if ( Result <= Previous) {
422 if (endptr !=
NULL) {
423 *endptr = (
char *)pEnd;
447 unsigned long long Result = 0;
448 unsigned long long Previous;
453 if ((base < 0) || (base == 1) || (base > 36)) {
454 if (endptr !=
NULL) {
473 if (
toupper (nptr[1]) ==
'X') {
475 if ((base == 0) || (base == 16)) {
481 if ((base == 0) || (base == 8)) {
494 for ( ; *nptr ==
'0'; ++nptr) {
503 Result =
DivU64x32 (Result, base) + (
unsigned long long)temp;
504 if ( Result < Previous) {
515 if (endptr !=
NULL) {
516 *endptr = (
char *)pEnd;
548 const char *__restrict nptr,
549 char **__restrict endptr
563 DEBUG ((DEBUG_WARN,
"%a: \"%a\" We don't support double type on edk2 yet. Only integer part is returned: %d\n", __func__, nptr, Data));
570 if (endptr !=
NULL) {
572 *endptr = (
char *__restrict)nptr +
StrLen;
578static UINT8 BitMask[] = {
579 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
582#define WHICH8(c) ((unsigned char)(c) >> 3)
583#define WHICH_BIT(c) (BitMask[((c) & 0x7)])
584#define BITMAP64 ((UINT64 *)bitmap)
589 unsigned char *bitmap,
598 for (BITMAP64[0] = index = 1; index < n; index++) {
603 for ( ; *s2 !=
'\0'; s2++) {
604 index = WHICH8 (*s2);
605 bit = WHICH_BIT (*s2);
606 bitmap[index] = bitmap[index] | bit;
622 UINT8 bitmap[(((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
626 BuildBitmap (bitmap, s2,
sizeof (bitmap) /
sizeof (UINT64));
628 for ( ; *s1 !=
'\0'; ++s1) {
629 index = WHICH8 (*s1);
630 bit = WHICH_BIT (*s1);
631 if ((bitmap[index] & bit) != 0) {
656 return errnum_message;
671 NumSize = Num * Size;
674 RetVal = malloc (NumSize);
675 if ( RetVal !=
NULL) {
676 (VOID)
ZeroMem (RetVal, NumSize);
680 DEBUG ((DEBUG_POOL,
"0x%p = calloc(%d, %d)\n", RetVal, Num, Size));
690UINTN CumulativeDays[2][14] = {
698 31 + 28 + 31 + 30 + 31,
699 31 + 28 + 31 + 30 + 31 + 30,
700 31 + 28 + 31 + 30 + 31 + 30 + 31,
701 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,
702 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
703 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
704 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
705 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31
714 31 + 29 + 31 + 30 + 31,
715 31 + 29 + 31 + 30 + 31 + 30,
716 31 + 29 + 31 + 30 + 31 + 30 + 31,
717 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,
718 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,
719 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,
720 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,
721 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31
725#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
726#define SECSPERMIN (60)
727#define SECSPERHOUR (60 * 60)
728#define SECSPERDAY (24 * SECSPERHOUR)
751 for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {
752 CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
760 (time_t)(CumulativeDays[IsLeap (Time.Year)][Time.Month] * SECSPERDAY) +
761 (time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) +
762 (time_t)(Time.Hour * SECSPERHOUR) +
763 (time_t)(Time.Minute * 60) +
781 int ( *compare )(
const void *,
const void *)
784 ASSERT (base !=
NULL);
785 ASSERT (compare !=
NULL);
813 const char *filename,
905 CHAR8 FormatStringParamater;
907 while (*(FormatString + *CurrentPosition) !=
's') {
913 FormatStringParamater = *(FormatString + *CurrentPosition);
914 if ((FormatStringParamater !=
'-') &&
915 (FormatStringParamater !=
'+') &&
916 (FormatStringParamater !=
'*') &&
917 (FormatStringParamater !=
'.') &&
924 (*CurrentPosition)++;
925 if (*CurrentPosition >= StrLength) {
949 UINTN FormatStrIndex;
950 UINTN FormatStrSpecifier;
951 BOOLEAN PercentageMark;
952 CHAR8 *TempFormatBuffer;
953 BOOLEAN IsFormatString;
958 if (FormatString ==
NULL) {
963 if (FormatStrSize == 0) {
969 if (TempFormatBuffer ==
NULL) {
977 PercentageMark =
FALSE;
979 while (FormatStrIndex < FormatStrSize) {
980 if (PercentageMark ==
TRUE) {
984 PercentageMark =
FALSE;
985 if (*(FormatString + FormatStrIndex) !=
'%') {
987 FormatStrSpecifier = FormatStrIndex;
992 if ((FormatStrSpecifier - FormatStrIndex) != 0) {
994 (VOID *)(TempFormatBuffer + FormatStrIndex),
995 (VOID *)(FormatString + FormatStrIndex),
996 FormatStrSpecifier - FormatStrIndex
1000 FormatStrIndex = FormatStrSpecifier;
1001 if (IsFormatString ==
TRUE) {
1006 *(TempFormatBuffer + FormatStrSpecifier) =
'a';
1016 if (*(FormatString + FormatStrIndex) ==
'%') {
1020 PercentageMark =
TRUE;
1028 *(TempFormatBuffer + FormatStrIndex) = *(FormatString + FormatStrIndex);
1032 return TempFormatBuffer;
1054 OUT CHAR8 *StartOfBuffer,
1060 CHAR8 *TempFormatBuffer;
1061 UINTN LenStrProduced;
1069 if (TempFormatBuffer ==
NULL) {
1073 LenStrProduced =
AsciiVSPrint (StartOfBuffer, BufferSize, (
CONST CHAR8 *)TempFormatBuffer, Marker);
1075 return LenStrProduced;
1098 OUT CHAR8 *StartOfBuffer,
1105 UINTN LenStrProduced;
1109 return LenStrProduced;
UINT64 EFIAPI DivU64x32(IN UINT64 Dividend, IN UINT32 Divisor)
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
RETURN_STATUS EFIAPI AsciiStrDecimalToUintnS(IN CONST CHAR8 *String, OUT CHAR8 **EndPointer OPTIONAL, OUT UINTN *Data)
INT64 EFIAPI MultS64x64(IN INT64 Multiplicand, IN INT64 Multiplier)
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
EFI_RUNTIME_SERVICES * gRT
#define VA_START(Marker, Parameter)
#define DEBUG(Expression)
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
CHAR8 * ReplaceUnicodeToAsciiStrFormat(IN CONST CHAR8 *FormatString)
time_t time(time_t *timer)
long strtol(const char *nptr, char **endptr, int base)
char * strerror(int errnum)
double strtod(const char *__restrict nptr, char **__restrict endptr)
char * strpbrk(const char *s1, const char *s2)
FILE * fopen(const char *filename, const char *mode)
size_t fwrite(const void *ptr, size_t size, size_t count, FILE *stream)
void qsort(void *base, size_t num, size_t width, int(*compare)(const void *, const void *))
UINTN EFIAPI RedfishAsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
BOOLEAN CheckFormatingString(IN CONST CHAR8 *FormatString, IN OUT UINTN *CurrentPosition, IN UINTN StrLength)
char * strdup(const char *str)
UINTN EFIAPI RedfishAsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
unsigned long long strtoull(const char *nptr, char **endptr, int base)
size_t fread(void *ptr, size_t size, size_t count, FILE *stream)
long long strtoll(const char *nptr, char **endptr, int base)
VOID EFIAPI PerformQuickSort(IN OUT VOID *BufferToSort, IN CONST UINTN Count, IN CONST UINTN ElementSize, IN SORT_COMPARE CompareFunction)
#define EFI_UNSPECIFIED_TIMEZONE