From nobody Sun Apr 28 21:59:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+70837+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70837+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=hpe.com ARC-Seal: i=1; a=rsa-sha256; t=1611805616; cv=none; d=zohomail.com; s=zohoarc; b=L5TTHWKIDRuTNwQfbeYdot/4aScAYVytwoMB6vllUZTiC4OGnsxjKFslzpfBdC6aHUdtakmGsyr342w6era3v9c0sXgqF8yyDpbyeE2z70w3ZN8Qv8A08/gCJKSToZYRyK0ykrv7ylTJKkEmYhgnVoVrb73KzMcLtAEsiPLVsTg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611805616; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=i+smxxKFYW6xhxJcTIM7cMpXGSvQa6/JPS/f7zWE+hw=; b=Ah8NElMwC/St19FxAUfbKIxupz/Q26IpmwR6Dgw+4krJjb6EUgkiZpaH4BoP9Ylek7TVKHGy2AUTWJVnKFID9IYidsTu8VD71S/h7M2L2Smeg9Ab28uae3nMGbsSJMwxTMZ4scZvoSDf0NftJPEr5pFTXUvWBrU8J+gCSGgSM8w= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+70837+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1611805616576539.362610277316; Wed, 27 Jan 2021 19:46:56 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id PEQFYY1788612xz2XDg5ztGB; Wed, 27 Jan 2021 19:46:56 -0800 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web09.19995.1611805610330127142 for ; Wed, 27 Jan 2021 19:46:50 -0800 X-Received: from pps.filterd (m0148664.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10S3XrHg026384; Thu, 28 Jan 2021 03:46:49 GMT X-Received: from g4t3426.houston.hpe.com (g4t3426.houston.hpe.com [15.241.140.75]) by mx0b-002e3701.pphosted.com with ESMTP id 36avp42ru6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 28 Jan 2021 03:46:49 +0000 X-Received: from g4t3433.houston.hpecorp.net (g4t3433.houston.hpecorp.net [16.208.49.245]) by g4t3426.houston.hpe.com (Postfix) with ESMTP id BCACF4E; Thu, 28 Jan 2021 03:46:48 +0000 (UTC) X-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 8336345; Thu, 28 Jan 2021 03:46:47 +0000 (UTC) From: "Abner Chang" To: devel@edk2.groups.io Cc: Nickle Wang , Leif Lindholm , Michael D Kinney Subject: [edk2-devel] [PATCH v2] RedfishPkg/RedfishCrtLib: Add more CRT functions Date: Thu, 28 Jan 2021 10:58:04 +0800 Message-Id: <20210128025804.3108-1-abner.chang@hpe.com> X-HPE-SCL: -1 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,abner.chang@hpe.com X-Gm-Message-State: JRaikGjLajcOHPJ8baYhhCRLx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1611805616; bh=yUdvYeKbsD+Q+NnSTy/mZGPZvn69ce6jY9sO4jGJwEY=; h=Cc:Date:From:Reply-To:Subject:To; b=kvg4mq3REVUkVLHowWFu03IswsCM4bgyn7BQaIs7Qh20btruPgO/Bp8XwzPhJ4yXVDn Tbi6CzhOszQKYjmo8jtCZomNdv8Js5qCWuriUJ5C4RCIKec2+SK5WbPepVCHokRPmxGO+ gH4Ah41pIvz2mFc5ZqQdsG6oue41J+IwvGA= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 | 122 +++++++++++++++++- 1 file changed, 121 insertions(+), 1 deletion(-) diff --git a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c b/Redf= ishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c index 0696341bc0..58ef4f8fdb 100644 --- a/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c +++ b/RedfishPkg/PrivateLibrary/RedfishCrtLib/RedfishCrtLib.c @@ -15,6 +15,10 @@ #include =20 int errno =3D 0; +char errnum_message [] =3D "We don't support to map errnum to the error me= ssage on edk2 Redfish\n"; + +// This is required to keep VC++ happy if you use floating-point +int _fltused =3D 1; =20 /** Determine if a particular character is an alphanumeric character @@ -465,6 +469,77 @@ strtod (const char * __restrict nptr, char ** __restri= ct endptr) { return (double)0; } =20 +static UINT8 BitMask[] =3D { + 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] =3D index =3D 1; index < n; index++) { + BITMAP64[index] =3D 0; + } + + // Set bits in bitmap corresponding to the characters in s2 + for (; *s2 !=3D '\0'; s2++) { + index =3D WHICH8(*s2); + bit =3D WHICH_BIT(*s2); + bitmap[index] =3D bitmap[index] | bit; + } +} + +/** The strpbrk function locates the first occurrence in the string pointe= d 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 !=3D '\0'; ++s1) { + index =3D WHICH8(*s1); + bit =3D WHICH_BIT(*s1); + if( (bitmap[index] & bit) !=3D 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 m= ap + 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. **/ @@ -592,7 +667,52 @@ void qsort (void *base, size_t num, size_t width, int = (*compare)(const void *, c =20 **/ int fgetc(FILE * _File){ - return 0; + return EOF; +} +/** + 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 NULL; +} +/** + Read stream from file, we don't support file operastion on edk2 JSON lib= rary. + + @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 li= brary. + + @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 EOF; +} +/** + 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 -1; } /** This function check if this is the formating string specifier. --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#70837): https://edk2.groups.io/g/devel/message/70837 Mute This Topic: https://groups.io/mt/80176266/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-