#include #include #include #include "word.h" /** * strlcpy - Word sized bsd strlcpy. * @d: Destination * @s: Source * @n: Max @s */ size_t strlcpy(char *d, const char *s, size_t n) { char *z = d; size_t *wd; const size_t *ws; /* A byte for nul */ if (!n--) goto terminate; if ((uintptr_t)d % sizeof(size_t) != (uintptr_t)s % sizeof(size_t)) goto misaligned; for (; (uintptr_t)s % sizeof(size_t); *d++ = *s++, n--) if (!*s || !n) goto terminate; for (wd = (size_t *)d, ws= (const size_t *)s ; !word_has_zero(*ws) && n >= sizeof(size_t) ; *wd = *ws, wd++, ws++, n -= sizeof(size_t)) d = (char *)wd; s = (const char *)ws; misaligned: for (; (*d = *s) && n; d++, s++, n--); terminate: *d = '\0'; return d - z + strlen(s); }