From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web08.32564.1611552332186165148 for ; Sun, 24 Jan 2021 21:25:32 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@hpe.com header.s=pps0720 header.b=GvmFGHSa; spf=pass (domain: hpe.com, ip: 148.163.147.86, mailfrom: prvs=0659271e3c=abner.chang@hpe.com) Received: from pps.filterd (m0148663.ppops.net [127.0.0.1]) by mx0a-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10P5OCLZ010301; Mon, 25 Jan 2021 05:25:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hpe.com; h=from : to : cc : subject : date : message-id; s=pps0720; bh=j7zkK8eM6JhVqwtYe3Icklkpy5cVaPFIzFrYim31NnA=; b=GvmFGHSaBaHKBENt/JT16oeyL2jZJ6Z4ccTZwPfNDHLo7T6ZZnbG7Iq2iRAgkYRAUAQJ QpuMOWYigtSxKVW43GxmwPzLwDSxsSvEtGWGXW+yenChenMkkDXD3zg6t4/4T/irsaJ1 mR0+qZ8H2FPl9pvnwVZycvzITw+CG+ROCB7U9FwNBzOuwvD7gLN+l7cq6h+u5qDK2tCB gkCkwIbVycptr1kudtNeJ/AQYDLAGBGCBqXjT9Y9GJZPBAEBsCSlUgeBhrk/yPcnubZF TvjBEM6eiNrH9x8xhZv6YHJfDap5EQE54x0mIjRoKCtAk7c4I0WmcsZ868l2o0pGWDbm MQ== Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0a-002e3701.pphosted.com with ESMTP id 368wwf5qqm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 25 Jan 2021 05:25:31 +0000 Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id AAFD34E; Mon, 25 Jan 2021 05:25:30 +0000 (UTC) Received: from abner-virtual-machine.asiapacific.hpqcorp.net (abner-virtual-machine.asiapacific.hpqcorp.net [15.119.210.153]) by g4t3433.houston.hpecorp.net (Postfix) with ESMTP id 737CD49; Mon, 25 Jan 2021 05:25:29 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Nickle Wang , Leif Lindholm , Michael D Kinney Subject: [PATCH] RedfishPkg/RedfishCrtLib: Add more CRT functions Date: Mon, 25 Jan 2021 12:36:53 +0800 Message-Id: <20210125043653.20832-1-abner.chang@hpe.com> X-Mailer: git-send-email 2.17.1 X-HPE-SCL: -1 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-25_01:2021-01-22,2021-01-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 malwarescore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 spamscore=0 impostorscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101250030 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 Cc: Nickle Wang Cc: Leif Lindholm Cc: Michael D Kinney --- .../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 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