use restrict everywhere it's required by c99 and/or posix 2008
[musl] / src / string / stpcpy.c
1 #include <string.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <limits.h>
5 #include "libc.h"
6
7 #define ALIGN (sizeof(size_t)-1)
8 #define ONES ((size_t)-1/UCHAR_MAX)
9 #define HIGHS (ONES * (UCHAR_MAX/2+1))
10 #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
11
12 char *__stpcpy(char *restrict d, const char *restrict s)
13 {
14         size_t *wd;
15         const size_t *ws;
16
17         if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) {
18                 for (; (*d=*s) && ((uintptr_t)s & ALIGN); s++, d++);
19                 if (!*s) return d;
20                 wd=(void *)d; ws=(const void *)s;
21                 for (; !HASZERO(*ws); *wd++ = *ws++);
22                 d=(void *)wd; s=(const void *)ws;
23         }
24         for (; (*d=*s); s++, d++);
25
26         return d;
27 }
28
29 weak_alias(__stpcpy, stpcpy);