TianoCore EDK2 master
Loading...
Searching...
No Matches
RedfishCrtLib.c File Reference

Go to the source code of this file.

Macros

#define WHICH8(c)   ((unsigned char)(c) >> 3)
 
#define WHICH_BIT(c)   (BitMask[((c) & 0x7)])
 
#define BITMAP64   ((UINT64 *)bitmap)
 
#define IsLeap(y)   (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))
 
#define SECSPERMIN   (60)
 
#define SECSPERHOUR   (60 * 60)
 
#define SECSPERDAY   (24 * SECSPERHOUR)
 

Functions

int isalnum (int c)
 
int isdchar (int c)
 
int isspace (int c)
 
void * malloc (size_t size)
 
void free (void *ptr)
 
char * strdup (const char *str)
 
int toupper (IN int c)
 
int Digit2Val (int c)
 
long long strtoll (const char *nptr, char **endptr, int base)
 
long strtol (const char *nptr, char **endptr, int base)
 
unsigned long long strtoull (const char *nptr, char **endptr, int base)
 
double strtod (const char *__restrict nptr, char **__restrict endptr)
 
char * strpbrk (const char *s1, const char *s2)
 
char * strerror (int errnum)
 
void * calloc (size_t Num, size_t Size)
 
time_t time (time_t *timer)
 
void qsort (void *base, size_t num, size_t width, int(*compare)(const void *, const void *))
 
int fgetc (FILE *_File)
 
FILE * fopen (const char *filename, const char *mode)
 
size_t fread (void *ptr, size_t size, size_t count, FILE *stream)
 
size_t fwrite (const void *ptr, size_t size, size_t count, FILE *stream)
 
int fclose (FILE *stream)
 
int fprintf (FILE *stream, const char *format,...)
 
BOOLEAN CheckFormatingString (IN CONST CHAR8 *FormatString, IN OUT UINTN *CurrentPosition, IN UINTN StrLength)
 
CHAR8 * ReplaceUnicodeToAsciiStrFormat (IN CONST CHAR8 *FormatString)
 
UINTN EFIAPI RedfishAsciiVSPrint (OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
 
UINTN EFIAPI RedfishAsciiSPrint (OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
 

Variables

int errno = 0
 
char errnum_message [] = "We don't support to map errnum to the error message on edk2 Redfish\n"
 
int _fltused = 1
 
UINTN CumulativeDays [2][14]
 

Detailed Description

CRT wrapper functions for system call,the string operation functions are remodeled after edk2-libc.

Copyright (c) 2019, Intel Corporation. All rights reserved.
(C) Copyright 2020 Hewlett Packard Enterprise Development LP
Copyright (c) 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.

SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file RedfishCrtLib.c.

Macro Definition Documentation

◆ BITMAP64

#define BITMAP64   ((UINT64 *)bitmap)

Definition at line 584 of file RedfishCrtLib.c.

◆ IsLeap

#define IsLeap (   y)    (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))

Definition at line 725 of file RedfishCrtLib.c.

◆ SECSPERDAY

#define SECSPERDAY   (24 * SECSPERHOUR)

Definition at line 728 of file RedfishCrtLib.c.

◆ SECSPERHOUR

#define SECSPERHOUR   (60 * 60)

Definition at line 727 of file RedfishCrtLib.c.

◆ SECSPERMIN

#define SECSPERMIN   (60)

Definition at line 726 of file RedfishCrtLib.c.

◆ WHICH8

#define WHICH8 (   c)    ((unsigned char)(c) >> 3)

Definition at line 582 of file RedfishCrtLib.c.

◆ WHICH_BIT

#define WHICH_BIT (   c)    (BitMask[((c) & 0x7)])

Definition at line 583 of file RedfishCrtLib.c.

Function Documentation

◆ calloc()

void * calloc ( size_t  Num,
size_t  Size 
)

Allocate and zero-initialize array.

Definition at line 663 of file RedfishCrtLib.c.

◆ CheckFormatingString()

BOOLEAN CheckFormatingString ( IN CONST CHAR8 *  FormatString,
IN OUT UINTN CurrentPosition,
IN UINTN  StrLength 
)

This function check if this is the formating string specifier.

Parameters
[in]FormatStringA Null-terminated ASCII format string.
[in,out]CurrentPositionThe starting position at the given string to check for "[flags][width][.precision][length]s" string specifier.
[in]StrLengthMaximum string length.
Returns
BOOLEAN TRUE means this is the formating string specifier. CurrentPosition is returned at the position of "s". FALSE means this is not the formating string specifier.. CurrentPosition is returned at the position of failed character.

Definition at line 899 of file RedfishCrtLib.c.

◆ Digit2Val()

int Digit2Val ( int  c)

Digit to a value.

Returns
Returns the value of digit.

Definition at line 156 of file RedfishCrtLib.c.

◆ fclose()

int fclose ( FILE *  stream)

Close file, we don't support file operastion on edk2 JSON library.

Returns
0 Unsupported

Definition at line 861 of file RedfishCrtLib.c.

◆ fgetc()

int fgetc ( FILE *  _File)

Get character from stream, we don't support file operastion on edk2 JSON library.

Returns
Returns the character currently pointed by the internal file position indicator of the specified stream

Definition at line 798 of file RedfishCrtLib.c.

◆ fopen()

FILE * fopen ( const char *  filename,
const char *  mode 
)

Open stream file, we don't support file operastion on edk2 JSON library.

Returns
0 Unsupported

Definition at line 812 of file RedfishCrtLib.c.

◆ fprintf()

int fprintf ( FILE *  stream,
const char *  format,
  ... 
)

Write the formatted string to file, we don't support file operastion on edk2 JSON library.

Returns
0 Unsupported

Definition at line 875 of file RedfishCrtLib.c.

◆ fread()

size_t fread ( void *  ptr,
size_t  size,
size_t  count,
FILE *  stream 
)

Read stream from file, we don't support file operastion on edk2 JSON library.

Returns
0 Unsupported

Definition at line 827 of file RedfishCrtLib.c.

◆ free()

void free ( void *  ptr)

De-allocates or frees a memory block

Definition at line 91 of file RedfishCrtLib.c.

◆ fwrite()

size_t fwrite ( const void *  ptr,
size_t  size,
size_t  count,
FILE *  stream 
)

Write stream from file, we don't support file operastion on edk2 JSON library.

Returns
0 Unsupported

Definition at line 844 of file RedfishCrtLib.c.

◆ isalnum()

int isalnum ( int  c)

Determine if a particular character is an alphanumeric character

Returns
Returns 1 if c is an alphanumeric character, otherwise returns 0.

Definition at line 29 of file RedfishCrtLib.c.

◆ isdchar()

int isdchar ( int  c)

Determine if a particular character is a digital character

Returns
Returns 1 if c is an digital character, otherwise returns 0.

Definition at line 47 of file RedfishCrtLib.c.

◆ isspace()

int isspace ( int  c)

Determine if a particular character is a space character

Returns
Returns 1 if c is a space character

Definition at line 66 of file RedfishCrtLib.c.

◆ malloc()

void * malloc ( size_t  size)

Allocates memory blocks

Definition at line 80 of file RedfishCrtLib.c.

◆ qsort()

void qsort ( void *  base,
size_t  num,
size_t  width,
int(*)(const void *, const void *)  compare 
)

Performs a quick sort

Definition at line 777 of file RedfishCrtLib.c.

◆ RedfishAsciiSPrint()

UINTN EFIAPI RedfishAsciiSPrint ( OUT CHAR8 *  StartOfBuffer,
IN UINTN  BufferSize,
IN CONST CHAR8 *  FormatString,
  ... 
)

This is the Redfish version of CRT snprintf function, this function replaces "%s" to "%a" before invoking AsciiSPrint(). That is because "%s" is unicode base on edk2 environment however "%s" is ascii code base on snprintf(). See definitions of AsciiSPrint() for the details.

Parameters
StartOfBufferA pointer to the output buffer for the produced Null-terminated ASCII string.
BufferSizeThe size, in bytes, of the output buffer specified by StartOfBuffer.
FormatStringA Null-terminated ASCII format string.
...Variable argument list whose contents are accessed based on the format string specified by FormatString.
Returns
The number of ASCII characters in the produced output buffer not including the Null-terminator.

Definition at line 1097 of file RedfishCrtLib.c.

◆ RedfishAsciiVSPrint()

UINTN EFIAPI RedfishAsciiVSPrint ( OUT CHAR8 *  StartOfBuffer,
IN UINTN  BufferSize,
IN CONST CHAR8 *  FormatString,
IN VA_LIST  Marker 
)

This is the Redfish version of CRT vsnprintf function, this function replaces "%s" to "%a" before invoking AsciiVSPrint(). That is because "%s" is unicode base on edk2 environment however "%s" is ascii code base on vsnprintf(). See definitions of AsciiVSPrint() for the details.

Parameters
StartOfBufferA pointer to the output buffer for the produced Null-terminated ASCII string.
BufferSizeThe size, in bytes, of the output buffer specified by StartOfBuffer.
FormatStringA Null-terminated ASCII format string.
MarkerVA_LIST marker for the variable argument list.
Returns
The number of ASCII characters in the produced output buffer not including the Null-terminator.

Definition at line 1053 of file RedfishCrtLib.c.

◆ ReplaceUnicodeToAsciiStrFormat()

CHAR8 * ReplaceUnicodeToAsciiStrFormat ( IN CONST CHAR8 *  FormatString)

This function clones *FormatString however replaces "%s" with "%a" in the returned string.

Parameters
[in]ANull-terminated ASCII format string.
Returns
The new format string. Caller has to free the memory of this string using FreePool().

Definition at line 944 of file RedfishCrtLib.c.

◆ strdup()

char * strdup ( const char *  str)

NetBSD Compatibility Function strdup creates a duplicate copy of a string.

Returns
Returns the pointer to duplicated string.

Definition at line 110 of file RedfishCrtLib.c.

◆ strerror()

char * strerror ( int  errnum)

The strerror function maps the number in errnum to a message string. Typically, the values for errnum come from errno, but strerror shall map any value of type int to a message.

The implementation shall behave as if no library function calls the strerror function.

Returns
The strerror function returns a pointer to the string, the contents of which are locale specific. The array pointed to shall not be modified by the program, but may be overwritten by a subsequent call to the strerror function.

Definition at line 652 of file RedfishCrtLib.c.

◆ strpbrk()

char * strpbrk ( const char *  s1,
const char *  s2 
)

The strpbrk function locates the first occurrence in the string pointed to by s1 of any character from the string pointed to by s2.

Returns
The strpbrk function returns a pointer to the character, or a null pointer if no character from s2 occurs in s1.

Definition at line 617 of file RedfishCrtLib.c.

◆ strtod()

double strtod ( const char *__restrict  nptr,
char **__restrict  endptr 
)

edk2 Jansson port does not support doubles, simply return integer part.

These conversion functions convert the initial portion of the string pointed to by nptr to double, float, and long double representation, respectively.

The strtod(), strtof(), and strtold() functions return the converted value, if any.

If endptr is not NULL, a pointer to the character after the last charac- ter used in the conversion is stored in the location referenced by endptr.

If no conversion is performed, zero is returned and the value of nptr is stored in the location referenced by endptr.

If the correct value would cause overflow, plus or minus HUGE_VAL, HUGE_VALF, or HUGE_VALL is returned (according to the sign and type of the return value), and ERANGE is stored in errno. If the correct value would cause underflow, zero is returned and ERANGE is stored in errno.

Returns
Integer part of decimal number.

Definition at line 547 of file RedfishCrtLib.c.

◆ strtol()

long strtol ( const char *  nptr,
char **  endptr,
int  base 
)

The strtol, strtoll, strtoul, and strtoull functions convert the initial portion of the string pointed to by nptr to long int, long long int, unsigned long int, and unsigned long long int representation, respectively. First, they decompose the input string into three parts: an initial, possibly empty, sequence of white-space characters (as specified by the isspace function), a subject sequence resembling an integer represented in some radix determined by the value of base, and a final string of one or more unrecognized characters, including the terminating null character of the input string. Then, they attempt to convert the subject sequence to an integer, and return the result.

If the value of base is zero, the expected form of the subject sequence is that of an integer constant, optionally preceded by a plus or minus sign, but not including an integer suffix. If the value of base is between 2 and 36 (inclusive), the expected form of the subject sequence is a sequence of letters and digits representing an integer with the radix specified by base, optionally preceded by a plus or minus sign, but not including an integer suffix. The letters from a (or A) through z (or Z) are ascribed the values 10 through 35; only letters and digits whose ascribed values are less than that of base are permitted. If the value of base is 16, the characters 0x or 0X may optionally precede the sequence of letters and digits, following the sign if present.

The subject sequence is defined as the longest initial subsequence of the input string, starting with the first non-white-space character, that is of the expected form. The subject sequence contains no characters if the input string is empty or consists entirely of white space, or if the first non-white-space character is other than a sign or a permissible letter or digit.

If the subject sequence has the expected form and the value of base is zero, the sequence of characters starting with the first digit is interpreted as an integer constant. If the subject sequence has the expected form and the value of base is between 2 and 36, it is used as the base for conversion, ascribing to each letter its value as given above. If the subject sequence begins with a minus sign, the value resulting from the conversion is negated (in the return type). A pointer to the final string is stored in the object pointed to by endptr, provided that endptr is not a null pointer.

In other than the "C" locale, additional locale-specific subject sequence forms may be accepted.

If the subject sequence is empty or does not have the expected form, no conversion is performed; the value of nptr is stored in the object pointed to by endptr, provided that endptr is not a null pointer.

Returns
The strtol, strtoll, strtoul, and strtoull functions return the converted value, if any. If no conversion could be performed, zero is returned. If the correct value is outside the range of representable values, LONG_MIN, LONG_MAX, LLONG_MIN, LLONG_MAX, ULONG_MAX, or ULLONG_MAX is returned (according to the return type and sign of the value, if any), and the value of the macro ERANGE is stored in errno.

Definition at line 332 of file RedfishCrtLib.c.

◆ strtoll()

long long strtoll ( const char *  nptr,
char **  endptr,
int  base 
)

The strtoll function converts the initial portion of the string pointed to by nptr to long long int representation.

See the description for strtol for more information.

Returns
The strtoll function returns the converted value, if any. If no conversion could be performed, zero is returned. If the correct value is outside the range of representable values, LLONG_MIN or LLONG_MAX is returned (according to the sign of the value, if any), and the value of the macro ERANGE is stored in errno.

Definition at line 180 of file RedfishCrtLib.c.

◆ strtoull()

unsigned long long strtoull ( const char *  nptr,
char **  endptr,
int  base 
)

The strtoull function converts the initial portion of the string pointed to by nptr to unsigned long long int representation.

See the description for strtol for more information.

Returns
The strtoull function returns the converted value, if any. If no conversion could be performed, zero is returned. If the correct value is outside the range of representable values, ULLONG_MAX is returned and the value of the macro ERANGE is stored in errno.

Definition at line 440 of file RedfishCrtLib.c.

◆ time()

time_t time ( time_t *  timer)

Get the system time as seconds elapsed since midnight, January 1, 1970.

Definition at line 734 of file RedfishCrtLib.c.

◆ toupper()

int toupper ( IN int  c)

The toupper function converts a lowercase letter to a corresponding uppercase letter.

Parameters
[in]cThe character to be converted.
Returns
If the argument is a character for which islower is true and there are one or more corresponding characters, as specified by the current locale, for which isupper is true, the toupper function returns one of the corresponding characters (always the same one for any given locale); otherwise, the argument is returned unchanged.

Definition at line 139 of file RedfishCrtLib.c.

Variable Documentation

◆ _fltused

int _fltused = 1

Definition at line 22 of file RedfishCrtLib.c.

◆ CumulativeDays

UINTN CumulativeDays[2][14]

Definition at line 690 of file RedfishCrtLib.c.

◆ errno

int errno = 0

Copyright (c) 2024, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition at line 18 of file RedfishCrtLib.c.

◆ errnum_message

char errnum_message[] = "We don't support to map errnum to the error message on edk2 Redfish\n"

Definition at line 19 of file RedfishCrtLib.c.