#include #include // We won't be linked to standard library, but still need the basic mem* functions // so everything goes allright with the compiler // We use the "restrict" keyword on pointers so that the compiler knows it can // do more optimization on them (and as it's a much used function, it's good to // be able to do that) void* memcpy(void* restrict dest, const void* restrict src, size_t n) { uint8_t* restrict pdest = (uint8_t* restrict)dest; const uint8_t* restrict psrc = (const uint8_t* restrict)src; for (size_t i=0; i dest) { for (size_t i=0; i0; i--) { pdest[i-1] = psrc[i-1]; } } return dest; } int memcmp(const void* s1, const void* s2, size_t n) { const uint8_t* p1 = (const uint8_t*)s1; const uint8_t* p2 = (const uint8_t*)s2; for (size_t i=0; i