X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstring%2Fstrlcpy.c;h=ffa0b0b01458041a91f50d0d2c09f7ff2a8e828d;hb=d493206de7df4db07ad34f24701539ba0a6ed38c;hp=6aeb106aa2e032c4d392631bb8fa9dd8a9f2e8bb;hpb=cb8dff2149c393c94c2abbef186c564829b97e93;p=musl diff --git a/src/string/strlcpy.c b/src/string/strlcpy.c index 6aeb106a..ffa0b0b0 100644 --- a/src/string/strlcpy.c +++ b/src/string/strlcpy.c @@ -1,8 +1,7 @@ +#define _BSD_SOURCE #include -#include #include #include -#include "libc.h" #define ALIGN (sizeof(size_t)-1) #define ONES ((size_t)-1/UCHAR_MAX) @@ -13,10 +12,12 @@ size_t strlcpy(char *d, const char *s, size_t n) { char *d0 = d; size_t *wd; - const size_t *ws; if (!n--) goto finish; - if (((uintptr_t)s & ALIGN) != ((uintptr_t)d & ALIGN)) { +#ifdef __GNUC__ + typedef size_t __attribute__((__may_alias__)) word; + const word *ws; + if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); if (n && *s) { wd=(void *)d; ws=(const void *)s; @@ -25,6 +26,7 @@ size_t strlcpy(char *d, const char *s, size_t n) d=(void *)wd; s=(const void *)ws; } } +#endif for (; n && (*d=*s); n--, s++, d++); *d = 0; finish: