implement non-stub strverscmp
[musl] / src / string / memcpy.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4
5 #define SS (sizeof(size_t))
6 #define ALIGN (sizeof(size_t)-1)
7 #define ONES ((size_t)-1/UCHAR_MAX)
8
9 void *memcpy(void *restrict dest, const void *restrict src, size_t n)
10 {
11         unsigned char *d = dest;
12         const unsigned char *s = src;
13
14         if (((uintptr_t)d & ALIGN) != ((uintptr_t)s & ALIGN))
15                 goto misaligned;
16
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;
21
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++;
27         }
28         return dest;
29 }