public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions
@ 2021-01-25  4:36 Abner Chang
  2021-01-26 11:36 ` Leif Lindholm
  0 siblings, 1 reply; 3+ messages in thread
From: Abner Chang @ 2021-01-25  4:36 UTC (permalink / raw)
  To: devel; +Cc: Nickle Wang, Leif Lindholm, Michael D Kinney

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>
---
 .../RedfishCrtLib/RedfishCrtLib.c             | 119 ++++++++++++++++++
 1 file changed, 119 insertions(+)

diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
index 0696341bc0..c64f14534c 100644
--- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
+++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
@@ -15,6 +15,10 @@
 #include <Library/UefiRuntimeServicesTableLib.h>
 
 int  errno = 0;
+char errnum_message [] = "We don't support to map errnum to the error message on edk2 Redfish\n";
+
+// This is required to keep VC++ happy if you use floating-point
+int _fltused  = 1;
 
 /**
   Determine if a particular character is an alphanumeric character
@@ -465,6 +469,76 @@ strtod (const char * __restrict nptr, char ** __restrict endptr) {
     return (double)0;
 }
 
+static UINT8  BitMask[] = {
+  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
+  };
+
+#define WHICH8(c)     ((unsigned char)(c) >> 3)
+#define WHICH_BIT(c)  (BitMask[((c) & 0x7)])
+#define BITMAP64      ((UINT64 *)bitmap)
+
+static
+void
+BuildBitmap(unsigned char * bitmap, const char *s2, int n)
+{
+  unsigned char bit;
+  int           index;
+
+  // Initialize bitmap.  Bit 0 is always 1 which corresponds to '\0'
+  for (BITMAP64[0] = index = 1; index < n; index++)
+    BITMAP64[index] = 0;
+
+  // Set bits in bitmap corresponding to the characters in s2
+  for (; *s2 != '\0'; s2++) {
+    index = WHICH8(*s2);
+    bit = WHICH_BIT(*s2);
+    bitmap[index] = bitmap[index] | bit;
+  }
+}
+
+/** The strpbrk function locates the first occurrence in the string pointed to
+    by s1 of any character from the string pointed to by s2.
+
+    @return   The strpbrk function returns a pointer to the character, or a
+              null pointer if no character from s2 occurs in s1.
+**/
+char *
+strpbrk(const char *s1, const char *s2)
+{
+  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
+  UINT8 bit;
+  int index;
+
+  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
+
+  for( ; *s1 != '\0'; ++s1) {
+    index = WHICH8(*s1);
+    bit = WHICH_BIT(*s1);
+    if( (bitmap[index] & bit) != 0) {
+      return (char *)s1;
+    }
+  }
+  return NULL;
+}
+
+/** 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.
+
+    @return   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.
+**/
+char *
+strerror(int errnum)
+{
+  return errnum_message;
+}
+
 /**
   Allocate and zero-initialize array.
 **/
@@ -594,6 +668,51 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
 int fgetc(FILE * _File){
    return 0;
 }
+/**
+  Open stream file, we don't support file operastion on edk2 JSON library.
+
+  @return 0 Unsupported
+
+**/
+FILE *fopen (const char *filename, const char *mode) {
+  return 0;
+}
+/**
+  Read stream from file, we don't support file operastion on edk2 JSON library.
+
+  @return 0 Unsupported
+
+**/
+size_t fread (void * ptr, size_t size, size_t count, FILE * stream) {
+  return 0;
+}
+/**
+  Write stream from file, we don't support file operastion on edk2 JSON library.
+
+  @return 0 Unsupported
+
+**/
+size_t fwrite (const void * ptr, size_t size, size_t count, FILE * stream) {
+  return 0;
+}
+/**
+  Close file, we don't support file operastion on edk2 JSON library.
+
+  @return 0 Unsupported
+
+**/
+int fclose (FILE * stream) {
+  return 0;
+}
+/**
+  Write the formatted string to file, we don't support file operastion on edk2 JSON library.
+
+  @return 0 Unsupported
+
+**/
+int fprintf (FILE * stream, const char * format, ...) {
+  return 0;
+}
 /**
   This function check if this is the formating string specifier.
 
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions
  2021-01-25  4:36 [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions Abner Chang
@ 2021-01-26 11:36 ` Leif Lindholm
  2021-01-28  3:48   ` Abner Chang
  0 siblings, 1 reply; 3+ messages in thread
From: Leif Lindholm @ 2021-01-26 11:36 UTC (permalink / raw)
  To: Abner Chang; +Cc: devel, Nickle Wang, Michael D Kinney

On Mon, Jan 25, 2021 at 12:36:53 +0800, Abner Chang wrote:
> 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>
> ---
>  .../RedfishCrtLib/RedfishCrtLib.c             | 119 ++++++++++++++++++
>  1 file changed, 119 insertions(+)
> 
> diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> index 0696341bc0..c64f14534c 100644
> --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> @@ -15,6 +15,10 @@
>  #include <Library/UefiRuntimeServicesTableLib.h>
>  
>  int  errno = 0;
> +char errnum_message [] = "We don't support to map errnum to the error message on edk2 Redfish\n";
> +
> +// This is required to keep VC++ happy if you use floating-point
> +int _fltused  = 1;
>  
>  /**
>    Determine if a particular character is an alphanumeric character
> @@ -465,6 +469,76 @@ strtod (const char * __restrict nptr, char ** __restrict endptr) {
>      return (double)0;
>  }
>  
> +static UINT8  BitMask[] = {
> +  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
> +  };
> +
> +#define WHICH8(c)     ((unsigned char)(c) >> 3)
> +#define WHICH_BIT(c)  (BitMask[((c) & 0x7)])
> +#define BITMAP64      ((UINT64 *)bitmap)
> +
> +static
> +void
> +BuildBitmap(unsigned char * bitmap, const char *s2, int n)
> +{
> +  unsigned char bit;
> +  int           index;
> +
> +  // Initialize bitmap.  Bit 0 is always 1 which corresponds to '\0'
> +  for (BITMAP64[0] = index = 1; index < n; index++)
> +    BITMAP64[index] = 0;

Please use {}.

> +
> +  // Set bits in bitmap corresponding to the characters in s2
> +  for (; *s2 != '\0'; s2++) {
> +    index = WHICH8(*s2);
> +    bit = WHICH_BIT(*s2);
> +    bitmap[index] = bitmap[index] | bit;
> +  }
> +}
> +
> +/** The strpbrk function locates the first occurrence in the string pointed to
> +    by s1 of any character from the string pointed to by s2.
> +
> +    @return   The strpbrk function returns a pointer to the character, or a
> +              null pointer if no character from s2 occurs in s1.
> +**/
> +char *
> +strpbrk(const char *s1, const char *s2)
> +{
> +  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) & ~7U];
> +  UINT8 bit;
> +  int index;
> +
> +  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
> +
> +  for( ; *s1 != '\0'; ++s1) {
> +    index = WHICH8(*s1);
> +    bit = WHICH_BIT(*s1);
> +    if( (bitmap[index] & bit) != 0) {
> +      return (char *)s1;
> +    }
> +  }
> +  return NULL;
> +}
> +
> +/** 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.
> +
> +    @return   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.
> +**/
> +char *
> +strerror(int errnum)
> +{
> +  return errnum_message;
> +}
> +
>  /**
>    Allocate and zero-initialize array.
>  **/
> @@ -594,6 +668,51 @@ void qsort (void *base, size_t num, size_t width, int (*compare)(const void *, c
>  int fgetc(FILE * _File){
>     return 0;
>  }
> +/**
> +  Open stream file, we don't support file operastion on edk2 JSON library.
> +
> +  @return 0 Unsupported
> +
> +**/
> +FILE *fopen (const char *filename, const char *mode) {
> +  return 0;

NULL.

> +}
> +/**
> +  Read stream from file, we don't support file operastion on edk2 JSON library.
> +
> +  @return 0 Unsupported
> +
> +**/
> +size_t fread (void * ptr, size_t size, size_t count, FILE * stream) {
> +  return 0;
> +}
> +/**
> +  Write stream from file, we don't support file operastion on edk2 JSON library.
> +
> +  @return 0 Unsupported
> +
> +**/
> +size_t fwrite (const void * ptr, size_t size, size_t count, FILE * stream) {
> +  return 0;
> +}
> +/**
> +  Close file, we don't support file operastion on edk2 JSON library.
> +
> +  @return 0 Unsupported
> +
> +**/
> +int fclose (FILE * stream) {
> +  return 0;

0 indicated success. EOF should be returned otherwise.

> +}
> +/**
> +  Write the formatted string to file, we don't support file operastion on edk2 JSON library.
> +
> +  @return 0 Unsupported
> +
> +**/
> +int fprintf (FILE * stream, const char * format, ...) {
> +  return 0;

>From my linux manpage:
"If an output error is encountered, a negative value is returned."

/
    Leif

> +}
>  /**
>    This function check if this is the formating string specifier.
>  
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions
  2021-01-26 11:36 ` Leif Lindholm
@ 2021-01-28  3:48   ` Abner Chang
  0 siblings, 0 replies; 3+ messages in thread
From: Abner Chang @ 2021-01-28  3:48 UTC (permalink / raw)
  To: Leif Lindholm
  Cc: devel@edk2.groups.io, Wang, Nickle (HPS SW), Michael D Kinney

All fixed and v2 sent. Didn't pay attention on the return values. Thanks for catching this.

Abner

> -----Original Message-----
> From: Leif Lindholm [mailto:leif@nuviainc.com]
> Sent: Tuesday, January 26, 2021 7:37 PM
> To: Chang, Abner (HPS SW/FW Technologist) <abner.chang@hpe.com>
> Cc: devel@edk2.groups.io; Wang, Nickle (HPS SW) <nickle.wang@hpe.com>;
> Michael D Kinney <michael.d.kinney@intel.com>
> Subject: Re: [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions
> 
> On Mon, Jan 25, 2021 at 12:36:53 +0800, Abner Chang wrote:
> > 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>
> > ---
> >  .../RedfishCrtLib/RedfishCrtLib.c             | 119 ++++++++++++++++++
> >  1 file changed, 119 insertions(+)
> >
> > diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> > b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> > index 0696341bc0..c64f14534c 100644
> > --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> > +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c
> > @@ -15,6 +15,10 @@
> >  #include <Library/UefiRuntimeServicesTableLib.h>
> >
> >  int  errno = 0;
> > +char errnum_message [] = "We don't support to map errnum to the error
> > +message on edk2 Redfish\n";
> > +
> > +// This is required to keep VC++ happy if you use floating-point int
> > +_fltused  = 1;
> >
> >  /**
> >    Determine if a particular character is an alphanumeric character @@
> > -465,6 +469,76 @@ strtod (const char * __restrict nptr, char ** __restrict
> endptr) {
> >      return (double)0;
> >  }
> >
> > +static UINT8  BitMask[] = {
> > +  0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80
> > +  };
> > +
> > +#define WHICH8(c)     ((unsigned char)(c) >> 3)
> > +#define WHICH_BIT(c)  (BitMask[((c) & 0x7)])
> > +#define BITMAP64      ((UINT64 *)bitmap)
> > +
> > +static
> > +void
> > +BuildBitmap(unsigned char * bitmap, const char *s2, int n) {
> > +  unsigned char bit;
> > +  int           index;
> > +
> > +  // Initialize bitmap.  Bit 0 is always 1 which corresponds to '\0'
> > +  for (BITMAP64[0] = index = 1; index < n; index++)
> > +    BITMAP64[index] = 0;
> 
> Please use {}.
> 
> > +
> > +  // Set bits in bitmap corresponding to the characters in s2
> > +  for (; *s2 != '\0'; s2++) {
> > +    index = WHICH8(*s2);
> > +    bit = WHICH_BIT(*s2);
> > +    bitmap[index] = bitmap[index] | bit;
> > +  }
> > +}
> > +
> > +/** The strpbrk function locates the first occurrence in the string pointed
> to
> > +    by s1 of any character from the string pointed to by s2.
> > +
> > +    @return   The strpbrk function returns a pointer to the character, or a
> > +              null pointer if no character from s2 occurs in s1.
> > +**/
> > +char *
> > +strpbrk(const char *s1, const char *s2) {
> > +  UINT8 bitmap[ (((UCHAR_MAX + 1) / CHAR_BIT) + (CHAR_BIT - 1)) &
> > +~7U];
> > +  UINT8 bit;
> > +  int index;
> > +
> > +  BuildBitmap( bitmap, s2, sizeof(bitmap) / sizeof(UINT64));
> > +
> > +  for( ; *s1 != '\0'; ++s1) {
> > +    index = WHICH8(*s1);
> > +    bit = WHICH_BIT(*s1);
> > +    if( (bitmap[index] & bit) != 0) {
> > +      return (char *)s1;
> > +    }
> > +  }
> > +  return NULL;
> > +}
> > +
> > +/** 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.
> > +
> > +    @return   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.
> > +**/
> > +char *
> > +strerror(int errnum)
> > +{
> > +  return errnum_message;
> > +}
> > +
> >  /**
> >    Allocate and zero-initialize array.
> >  **/
> > @@ -594,6 +668,51 @@ void qsort (void *base, size_t num, size_t width,
> > int (*compare)(const void *, c  int fgetc(FILE * _File){
> >     return 0;
> >  }
> > +/**
> > +  Open stream file, we don't support file operastion on edk2 JSON library.
> > +
> > +  @return 0 Unsupported
> > +
> > +**/
> > +FILE *fopen (const char *filename, const char *mode) {
> > +  return 0;
> 
> NULL.
> 
> > +}
> > +/**
> > +  Read stream from file, we don't support file operastion on edk2 JSON
> library.
> > +
> > +  @return 0 Unsupported
> > +
> > +**/
> > +size_t fread (void * ptr, size_t size, size_t count, FILE * stream) {
> > +  return 0;
> > +}
> > +/**
> > +  Write stream from file, we don't support file operastion on edk2 JSON
> library.
> > +
> > +  @return 0 Unsupported
> > +
> > +**/
> > +size_t fwrite (const void * ptr, size_t size, size_t count, FILE *
> > +stream) {
> > +  return 0;
> > +}
> > +/**
> > +  Close file, we don't support file operastion on edk2 JSON library.
> > +
> > +  @return 0 Unsupported
> > +
> > +**/
> > +int fclose (FILE * stream) {
> > +  return 0;
> 
> 0 indicated success. EOF should be returned otherwise.
> 
> > +}
> > +/**
> > +  Write the formatted string to file, we don't support file operastion on
> edk2 JSON library.
> > +
> > +  @return 0 Unsupported
> > +
> > +**/
> > +int fprintf (FILE * stream, const char * format, ...) {
> > +  return 0;
> 
> From my linux manpage:
> "If an output error is encountered, a negative value is returned."
> 
> /
>     Leif
> 
> > +}
> >  /**
> >    This function check if this is the formating string specifier.
> >
> > --
> > 2.17.1
> >

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-28  3:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-25  4:36 [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions Abner Chang
2021-01-26 11:36 ` Leif Lindholm
2021-01-28  3:48   ` Abner Chang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox