diff --git a/build32/Makefile b/build32/Makefile index 862577a..97f02b4 100644 --- a/build32/Makefile +++ b/build32/Makefile @@ -38,7 +38,6 @@ SYS_OBJS = system/cpuid.o \ system/xhci.o LIB_OBJS = lib/barrier.o \ - lib/ctype.o \ lib/div64.o \ lib/print.o \ lib/read.o \ diff --git a/build64/Makefile b/build64/Makefile index 3346983..5e806fd 100644 --- a/build64/Makefile +++ b/build64/Makefile @@ -38,7 +38,6 @@ SYS_OBJS = system/cpuid.o \ system/xhci.o LIB_OBJS = lib/barrier.o \ - lib/ctype.o \ lib/print.o \ lib/read.o \ lib/string.o \ diff --git a/lib/ctype.c b/lib/ctype.c deleted file mode 100644 index cf06610..0000000 --- a/lib/ctype.c +++ /dev/null @@ -1,27 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -// Copyright (C) 2020 Martin Whitaker. - -#include "ctype.h" - -//------------------------------------------------------------------------------ -// Public Functions -//------------------------------------------------------------------------------ - -int toupper(int c) -{ - if (c >= 'a' && c <= 'z') { - return c + 'A' -'a'; - } else { - return c; - } -} - -int isdigit(int c) -{ - return c >= '0' && c <= '9'; -} - -int isxdigit(int c) -{ - return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F'); -} diff --git a/lib/ctype.h b/lib/ctype.h index f153018..a695d8c 100644 --- a/lib/ctype.h +++ b/lib/ctype.h @@ -14,18 +14,31 @@ * If c is a lower-case letter, returns its upper-case equivalent, otherwise * returns c. Assumes c is an ASCII character. */ -int toupper(int c); +static inline int toupper(int c) +{ + if (c >= 'a' && c <= 'z') { + return c + 'A' -'a'; + } else { + return c; + } +} /** * Returns 1 if c is a decimal digit, otherwise returns 0. Assumes c is an * ASCII character. */ -int isdigit(int c); +static inline int isdigit(int c) +{ + return c >= '0' && c <= '9'; +} /** * Returns 1 if c is a hexadecimal digit, otherwise returns 0. Assumes c is an * ASCII character. */ -int isxdigit(int c); +static inline int isxdigit(int c) +{ + return isdigit(c) || (toupper(c) >= 'A' && toupper(c) <= 'F'); +} #endif // CTYPE_H diff --git a/lib/string.c b/lib/string.c index 89f0f8d..257b6ce 100644 --- a/lib/string.c +++ b/lib/string.c @@ -43,16 +43,6 @@ int memcmp(const void *s1, const void *s2, size_t n) return 0; } -void *memcpy(void *dest, const void *src, size_t n) -{ - char *d = (char *)dest, *s = (char *)src; - - for (size_t i = 0; i < n; i++) { - d[i] = s[i]; - } - return dest; -} - void *memmove(void *dest, const void *src, size_t n) { char *d = (char *)dest, *s = (char *)src; @@ -74,16 +64,6 @@ void *memmove(void *dest, const void *src, size_t n) return dest; } -void *memset(void *s, int c, size_t n) -{ - char *d = (char *)s; - - for (size_t i = 0; i < n; i++) { - d[i] = c; - } - return s; -} - size_t strlen(const char *s) { size_t len = 0; diff --git a/lib/string.h b/lib/string.h index 37bd392..b24e704 100644 --- a/lib/string.h +++ b/lib/string.h @@ -24,8 +24,9 @@ int memcmp(const void *s1, const void *s2, size_t n); * Copies n bytes from the memory area pointed to by src to the memory area * pointed to by dest and returns a pointer to dest. The memory areas must * not overlap. + * void *memcpy(void *dst, const void *src, size_t n); */ -void *memcpy(void *dst, const void *src, size_t n); +#define memcpy(d, s, n) __builtin_memcpy((d), (s), (n)) /** * Copies n bytes from the memory area pointed to by src to the memory area @@ -37,8 +38,9 @@ void *memmove(void *dest, const void *src, size_t n); /** * Fills the first n bytes of the memory area pointed to by s with the byte * value c. + * void *memset(void *s, int c, size_t n); */ -void *memset(void *s, int c, size_t n); +#define memset(s, c, n) __builtin_memset((s), (c), (n)) /** * Returns the string length, excluding the terminating null character.