diff --git a/configure.ac b/configure.ac index 0c4f20f..6947d0b 100644 --- a/configure.ac +++ b/configure.ac @@ -113,9 +113,11 @@ AS_IF([test "$with_libc" = yes], [with_libc=yes], [with_libc ############# AS_IF([test "$enable_tests" = yes -a "$host_cpu" != "$build_cpu" ], AC_MSG_ERROR([can not build cross-platform tests])) -AS_IF([test "$enable_tests" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests])) AS_IF([test "$enable_tests_python" = yes -a "$host_cpu" != "$build_cpu" ], AC_MSG_ERROR([can not build cross-platform tests])) +AS_IF([test "$enable_tests" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests])) AS_IF([test "$enable_tests_python" = yes -a "$enable_freestanding" = yes], AC_MSG_ERROR([can not build freestanding tests])) +AS_IF([test "$enable_tests" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests])) +AS_IF([test "$enable_tests_python" = yes -a "$with_libc" = yes], AC_MSG_ERROR([can not use package `libc' with tests])) AS_IF([test "$with_printf" = yes -a "$with_ntoa" = no], AC_MSG_ERROR([package `printf' requires package `ntoa'])) AS_IF([test "$with_printf" = yes -a "$with_printf_fmt" = no], AC_MSG_ERROR([package `printf' requires package `printf-fmt'])) diff --git a/libc/string.h b/libc/string.h index 5be69eb..2808391 100644 --- a/libc/string.h +++ b/libc/string.h @@ -7,6 +7,7 @@ extern "C" { #include +int memcmp(const void *s1, const void *s2, size_t n); void *memcpy(void *dest, const void *src, size_t n); void *memmove(void *dest, const void *src, size_t n); void *memset(void *s, int c, size_t n); diff --git a/src/libc.c b/src/libc.c index 7394aa1..2ecb1a1 100644 --- a/src/libc.c +++ b/src/libc.c @@ -29,10 +29,18 @@ int isspace(const int c) return c == ' ' || (unsigned)c - '\t' < 5; } +int memcmp(const void *s1, const void *s2, size_t n) +{ + for (const unsigned char *p1 = s1, *p2 = s2; n--; ++p1, ++p2) { + if (*p1 != *p2) return *p1 - *p2; + } + return 0; +} + void *memcpy(void *dest, const void *src, size_t n) { char *dest_cell = dest; - char *src_cell = src; + char *src_cell = (char*)src; while (n--) *dest_cell++ = *src_cell++; return dest; } @@ -40,7 +48,7 @@ void *memcpy(void *dest, const void *src, size_t n) void *memmove(void *dest, const void *src, size_t n) { char *dest_cell = dest; - char *src_cell = src; + char *src_cell = (char*)src; if (dest_cell <= src_cell) { while (n--) *dest_cell++ = *src_cell++; } else {