From 766aac4d5cfbe76026be5ce718b0883ee211f323 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Tue, 9 Mar 2021 11:54:58 -0500 Subject: Consolidate most of our standard lib functions to lib Signed-off-by: Peter Jones --- Cryptlib/Include/OpenSslSupport.h | 23 +---------- Cryptlib/Makefile | 3 +- Cryptlib/SysCall/BaseStrings.c | 34 +--------------- Cryptlib/SysCall/CrtWrapper.c | 82 --------------------------------------- Cryptlib/SysCall/memset.c | 40 ------------------- 5 files changed, 4 insertions(+), 178 deletions(-) delete mode 100644 Cryptlib/SysCall/memset.c (limited to 'Cryptlib') diff --git a/Cryptlib/Include/OpenSslSupport.h b/Cryptlib/Include/OpenSslSupport.h index 7af9650f..6bb7ba64 100644 --- a/Cryptlib/Include/OpenSslSupport.h +++ b/Cryptlib/Include/OpenSslSupport.h @@ -288,34 +288,21 @@ extern int errno; void *malloc (size_t); void *realloc (void *, size_t); void free (void *); -int isdigit (int); -int isspace (int); -int tolower (int); -int isupper (int); -int isxdigit (int); -int isalnum (int); void *memcpy (void *, const void *, size_t); void *memset (void *, int, size_t); void *memchr (const void *, int, size_t); int memcmp (const void *, const void *, size_t); void *memmove (void *, const void *, size_t); -int strcmp (const char *, const char *); -int strncmp (const char *, const char *, size_t); char *strcpy (char *, const char *); char *strncpy (char *, const char *, size_t); -size_t strlen (const char *); char *strcat (char *, const char *); char *strchr (const char *, int); int strcasecmp (const char *, const char *); int strncasecmp (const char *, const char *, size_t); char *strncpy (char *, const char *, size_t); -int strncmp (const char *, const char *, size_t); -char *strrchr (const char *, int); unsigned long strtoul (const char *, char **, int); long strtol (const char *, char **, int); char *strerror (int); -size_t strspn (const char *, const char *); -size_t strcspn (const char *, const char *); int printf (const char *, ...); int sscanf (const char *, const char *, ...); int open (const char *, int, ...); @@ -351,7 +338,6 @@ gid_t getegid (void); void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); char *getenv (const char *); void exit (int); -void abort (void); __sighandler_t *signal (int, __sighandler_t *); // @@ -361,7 +347,7 @@ extern FILE *stderr; extern FILE *stdin; extern FILE *stdout; -#define AsciiStrLen(x) strlena(x) +#define AsciiStrLen(x) strlen(x) #define AsciiStrnCmp(s1, s2, len) strncmpa((CHAR8 *)s1, (CHAR8 *)s2, len) // @@ -372,17 +358,10 @@ extern FILE *stdout; #define memchr(buf,ch,count) ScanMem8((CHAR8 *)buf,(UINTN)(count),ch) #define memcmp(buf1,buf2,count) (int)(CompareMem(buf1,buf2,(UINTN)(count))) #define memmove(dest,source,count) CopyMem(dest,source,(UINTN)(count)) -#define strlen(str) (size_t)(AsciiStrLen((CHAR8 *)str)) -#define strcpy(strDest,strSource) AsciiStrCpy((CHAR8 *)strDest,(const CHAR8 *)strSource) -#define strncpy(strDest,strSource,count) AsciiStrnCpy((CHAR8 *)strDest,(const CHAR8 *)strSource,(UINTN)count) -#define strcat(strDest,strSource) AsciiStrCat((CHAR8 *)strDest,(const CHAR8 *)strSource) -#define strchr(str,ch) (char *)(ScanMem8((CHAR8 *)str,AsciiStrSize((CHAR8 *)str),ch)) -#define strncmp(string1,string2,count) (int)(AsciiStrnCmp((const CHAR8 *)string1, (const CHAR8 *)string2,(UINTN)(count))) #define localtime(timer) NULL #define assert(expression) #define atoi(nptr) AsciiStrDecimalToUintn((const CHAR8 *)nptr) #define gettimeofday(tvp,tz) do { (tvp)->tv_sec = time(NULL); (tvp)->tv_usec = 0; } while (0) #define gmtime_r(timer,result) (result = NULL) -#define abort() #endif diff --git a/Cryptlib/Makefile b/Cryptlib/Makefile index 65a3918c..27614618 100644 --- a/Cryptlib/Makefile +++ b/Cryptlib/Makefile @@ -63,8 +63,7 @@ OBJS = Hash/CryptMd4Null.o \ SysCall/CrtWrapper.o \ SysCall/TimerWrapper.o \ SysCall/BaseMemAllocation.o \ - SysCall/BaseStrings.o \ - SysCall/memset.o + SysCall/BaseStrings.o all: $(TARGET) diff --git a/Cryptlib/SysCall/BaseStrings.c b/Cryptlib/SysCall/BaseStrings.c index c4b3e18e..29a16100 100644 --- a/Cryptlib/SysCall/BaseStrings.c +++ b/Cryptlib/SysCall/BaseStrings.c @@ -3,7 +3,7 @@ CHAR8 * AsciiStrCat(CHAR8 *Destination, const CHAR8 *Source) { - UINTN dest_len = strlena((CHAR8 *)Destination); + UINTN dest_len = strlen((CHAR8 *)Destination); UINTN i; for (i = 0; Source[i] != '\0'; i++) @@ -61,37 +61,7 @@ WriteUnaligned32(UINT32 *Buffer, UINT32 Value) UINTN AsciiStrSize(const CHAR8 *string) { - return strlena(string) + 1; -} - -int -strcmp (const char *str1, const char *str2) -{ - return strcmpa((CHAR8 *)str1,(CHAR8 *)str2); -} - -inline static char -toupper (char c) -{ - return ((c >= 'a' && c <= 'z') ? c - ('a' - 'A') : c); -} - -/* Based on AsciiStriCmp() in edk2 MdePkg/Library/BaseLib/String.c */ -int -strcasecmp (const char *str1, const char *str2) -{ - char c1, c2; - - c1 = toupper (*str1); - c2 = toupper (*str2); - while ((*str1 != '\0') && (c1 == c2)) { - str1++; - str2++; - c1 = toupper (*str1); - c2 = toupper (*str2); - } - - return c1 - c2; + return strlen(string) + 1; } /* Based on AsciiStrDecimalToUintnS() in edk2 diff --git a/Cryptlib/SysCall/CrtWrapper.c b/Cryptlib/SysCall/CrtWrapper.c index 698e1eef..4bdaede9 100644 --- a/Cryptlib/SysCall/CrtWrapper.c +++ b/Cryptlib/SysCall/CrtWrapper.c @@ -121,21 +121,6 @@ QuickSortWorker ( // -- String Manipulation Routines -- // -/* Scan a string for the last occurrence of a character */ -char *strrchr (const char *str, int c) -{ - char * save; - - for (save = NULL; ; ++str) { - if (*str == c) { - save = (char *)str; - } - if (*str == 0) { - return (save); - } - } -} - /* Read formatted data from a string */ int sscanf (const char *buffer, const char *format, ...) { @@ -146,59 +131,6 @@ int sscanf (const char *buffer, const char *format, ...) return 0; } -// -// -- Character Classification Routines -- -// - -/* Determines if a particular character is a decimal-digit character */ -int isdigit (int c) -{ - // - // ::= [0-9] - // - return (('0' <= (c)) && ((c) <= '9')); -} - -/* Determine if an integer represents character that is a hex digit */ -int isxdigit (int c) -{ - // - // ::= [0-9] | [a-f] | [A-F] - // - return ((('0' <= (c)) && ((c) <= '9')) || - (('a' <= (c)) && ((c) <= 'f')) || - (('A' <= (c)) && ((c) <= 'F'))); -} - -/* Determines if a particular character represents a space character */ -int isspace (int c) -{ - // - // ::= [ ] - // - return ((c) == ' '); -} - -/* Determine if a particular character is an alphanumeric character */ -int isalnum (int c) -{ - // - // ::= [0-9] | [a-z] | [A-Z] - // - return ((('0' <= (c)) && ((c) <= '9')) || - (('a' <= (c)) && ((c) <= 'z')) || - (('A' <= (c)) && ((c) <= 'Z'))); -} - -/* Determines if a particular character is in upper case */ -int isupper (int c) -{ - // - // := [A-Z] - // - return (('A' <= (c)) && ((c) <= 'Z')); -} - // // -- Data Conversion Routines -- // @@ -223,15 +155,6 @@ unsigned long strtoul (const char *nptr, char **endptr, int base) return 0; } -/* Convert character to lowercase */ -int tolower (int c) -{ - if (('A' <= (c)) && ((c) <= 'Z')) { - return (c - ('A' - 'a')); - } - return (c); -} - // // -- Searching and Sorting Routines -- // @@ -424,11 +347,6 @@ int stat (const char *c, struct stat *s) return -1; } -int strncasecmp (const char *c, const char *s, size_t l) -{ - return 0; -} - void syslog (int a, const char *c, ...) { diff --git a/Cryptlib/SysCall/memset.c b/Cryptlib/SysCall/memset.c deleted file mode 100644 index 76deed68..00000000 --- a/Cryptlib/SysCall/memset.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 SUSE LINUX GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -typedef UINTN size_t; - -void * -memset (void *dest, int ch, size_t count) -{ - SetMem(dest, count, (UINT8)(ch)); - return dest; -} -- cgit v1.2.3