build.sh: pass OPTS also to linking stage, so -static can be passed
[rofl0r-memcpy-test.git] / musl_093.c
blob441e3bb0df4324cfddc617cbc28283ef5f26fc72
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdint.h>
5 #define SS (sizeof(size_t))
6 #define ALIGN (sizeof(size_t)-1)
7 #define ONES ((size_t)-1/UCHAR_MAX)
9 void *mymemcpy(void *dest, const void *src, size_t n)
11 unsigned char *d = dest;
12 const unsigned char *s = src;
14 if (((uintptr_t)d & ALIGN) != ((uintptr_t)s & ALIGN))
15 goto misaligned;
17 for (; ((uintptr_t)d & ALIGN) && n; n--) *d++ = *s++;
18 if (n) {
19 size_t *wd = (void *)d;
20 const size_t *ws = (const void *)s;
22 for (; n>=SS; n-=SS) *wd++ = *ws++;
23 d = (void *)wd;
24 s = (const void *)ws;
25 misaligned:
26 for (; n; n--) *d++ = *s++;
28 return dest;