]> git.proxmox.com Git - mirror_edk2.git/commitdiff
RedfishPkg/RedfishCrtLib: Add more CRT functions
authorAbner Chang <abner.chang@hpe.com>
Mon, 25 Jan 2021 03:35:46 +0000 (11:35 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 24 Feb 2021 07:58:50 +0000 (07:58 +0000)
Add more functions which were missed in the first time commit,
that causes the build error with EDK2 Redfish feature driver.

strerror - We don't support this on edk2 environment.
strpbrk  - Cloned this function from edk2-LibC
File operation functions - Not supported on edk2 environment.

Signed-off-by: Abner Chang <abner.chang@hpe.com>
Cc: Nickle Wang <nickle.wang@hpe.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Nickle Wang <nickle.wang@hpe.com>
Acked-by: Leif Lindholm <leif@nuviainc.com>
RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c

index 0696341bc035cb70da5ec61068dfcb4ec07b0b3e..58ef4f8fdbbe434a5de6eed37fd2acb567920800 100644 (file)
 #include <Library/UefiRuntimeServicesTableLib.h>\r
 \r
 int  errno = 0;\r
+char errnum_message [] = "We don't support to map errnum to the error message on edk2 Redfish\n";\r
+\r
+// This is required to keep VC++ happy if you use floating-point\r
+int _fltused  = 1;\r
 \r
 /**\r
   Determine if a particular character is an alphanumeric character\r
@@ -465,6 +469,77 @@ strtod (const char * __restrict nptr, char ** __restrict endptr) {
     return (double)0;\r
 }\r
 \r
+static UINT8  BitMask[] = {\r
+  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80\r
+  };\r
+\r
+#define WHICH8(c)     ((unsigned char)(c) >> 3)\r
+#define WHICH_BIT(c)  (BitMask[((c) & 0x7)])\r
+#define BITMAP64      ((UINT64 *)bitmap)\r
+\r
+static\r
+void\r
+BuildBitmap(unsigned char * bitmap, const char *s2, int n)\r
+{\r
+  unsigned char bit;\r
+  int           index;\r
+\r
+  // Initialize bitmap.  Bit 0 is always 1 which corresponds to '\0'\r
+  for (BITMAP64[0] = index = 1; index < n; index++) {\r
+    BITMAP64[index] = 0;\r
+  }\r
+\r
+  // Set bits in bitmap corresponding to the characters in s2\r
+  for (; *s2 != '\0'; s2++) {\r
+    index = WHICH8(*s2);\r
+    bit = WHICH_BIT(*s2);\r
+    bitmap[index] = bitmap[index] | bit;\r
+  }\r
+}\r
+\r
+/** The strpbrk function locates the first occurrence in the string pointed to\r
+    by s1 of any character from the string pointed to by s2.\r
+\r
+    @return   The strpbrk function returns a pointer to the character, or a\r
+              null pointer if no character from s2 occurs in s1.\r
+**/\r
+char *\r
+strpbrk(const char *s1, const char *s2)\r
+{\r
+  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];\r
+  UINT8 bit;\r
+  int index;\r
+\r
+  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));\r
+\r
+  for( ; *s1 != '\0'; ++s1) {\r
+    index = WHICH8(*s1);\r
+    bit = WHICH_BIT(*s1);\r
+    if( (bitmap[index] & bit) != 0) {\r
+      return (char *)s1;\r
+    }\r
+  }\r
+  return NULL;\r
+}\r
+\r
+/** The strerror function maps the number in errnum to a message string.\r
+    Typically, the values for errnum come from errno, but strerror shall map\r
+    any value of type int to a message.\r
+\r
+    The implementation shall behave as if no library function calls the\r
+    strerror function.\r
+\r
+    @return   The strerror function returns a pointer to the string, the\r
+              contents of which are locale specific.  The array pointed to\r
+              shall not be modified by the program, but may be overwritten by\r
+              a subsequent call to the strerror function.\r
+**/\r
+char *\r
+strerror(int errnum)\r
+{\r
+  return errnum_message;\r
+}\r
+\r
 /**\r
   Allocate and zero-initialize array.\r
 **/\r
@@ -592,7 +667,52 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
 \r
 **/\r
 int fgetc(FILE * _File){\r
-   return 0;\r
+   return EOF;\r
+}\r
+/**\r
+  Open stream file, we don't support file operastion on edk2 JSON library.\r
+\r
+  @return 0 Unsupported\r
+\r
+**/\r
+FILE *fopen (const char *filename, const char *mode) {\r
+  return NULL;\r
+}\r
+/**\r
+  Read stream from file, we don't support file operastion on edk2 JSON library.\r
+\r
+  @return 0 Unsupported\r
+\r
+**/\r
+size_t fread (void * ptr, size_t size, size_t count, FILE * stream) {\r
+  return 0;\r
+}\r
+/**\r
+  Write stream from file, we don't support file operastion on edk2 JSON library.\r
+\r
+  @return 0 Unsupported\r
+\r
+**/\r
+size_t fwrite (const void * ptr, size_t size, size_t count, FILE * stream) {\r
+  return 0;\r
+}\r
+/**\r
+  Close file, we don't support file operastion on edk2 JSON library.\r
+\r
+  @return 0 Unsupported\r
+\r
+**/\r
+int fclose (FILE * stream) {\r
+  return EOF;\r
+}\r
+/**\r
+  Write the formatted string to file, we don't support file operastion on edk2 JSON library.\r
+\r
+  @return 0 Unsupported\r
+\r
+**/\r
+int fprintf (FILE * stream, const char * format, ...) {\r
+  return -1;\r
 }\r
 /**\r
   This function check if this is the formating string specifier.\r