6 #define ALIGN (sizeof(size_t)-1)
7 #define ONES ((size_t)-1/UCHAR_MAX)
8 #define HIGHS (ONES * (UCHAR_MAX/2+1))
9 #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS)
11 size_t strlcpy(char *d
, const char *s
, size_t n
)
16 if (!n
--) goto finish
;
18 typedef size_t __attribute__((__may_alias__
)) word
;
20 if (((uintptr_t)s
& ALIGN
) == ((uintptr_t)d
& ALIGN
)) {
21 for (; ((uintptr_t)s
& ALIGN
) && n
&& (*d
=*s
); n
--, s
++, d
++);
23 wd
=(void *)d
; ws
=(const void *)s
;
24 for (; n
>=sizeof(size_t) && !HASZERO(*ws
);
25 n
-=sizeof(size_t), ws
++, wd
++) *wd
= *ws
;
26 d
=(void *)wd
; s
=(const void *)ws
;
30 for (; n
&& (*d
=*s
); n
--, s
++, d
++);
33 return d
-d0
+ strlen(s
);