Commit 1d3163ec authored by Ulrich Huber's avatar Ulrich Huber
Browse files

[fix] Implement memcmp instead of relying on gcc-builtin

parent 281baae1
......@@ -6,6 +6,7 @@
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
void *memmove(void *dst_void, const void *src_void, size_t length);
int memcmp(const void *s1, const void *s2, size_t n);
char *strncpy(char *dest, const char *src, size_t n);
......@@ -18,7 +19,6 @@ size_t strnlen(const char *s, size_t maxlen);
char * strtok(char *string, const char *delimiters);
#define memchr __builtin_memchr
#define memcmp __builtin_memcmp
#define strcat __builtin_strcat
#define strchr __builtin_strchr
......
......@@ -4,6 +4,7 @@ target_sources(
toki-libc-repl
#
PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/memcmp.c"
"${CMAKE_CURRENT_LIST_DIR}/memcpy.c"
"${CMAKE_CURRENT_LIST_DIR}/memmove.S"
"${CMAKE_CURRENT_LIST_DIR}/memset.c"
......
#include <stddef.h>
int memcmp(const void *s1, const void *s2, size_t n)
{
unsigned char *c1 = (unsigned char *) s1;
unsigned char *c2 = (unsigned char *) s2;
while (c1 - (unsigned char *)s1 < n && *c1 == *c2)
{
c1++;
c2++;
}
return *c1 - *c2;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment