5 #define SS (sizeof(size_t))
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 void *memchr(const void *src
, int c
, size_t n
)
13 const unsigned char *s
= src
;
15 for (; ((uintptr_t)s
& ALIGN
) && n
&& *s
!= c
; s
++, n
--);
19 for (w
= (const void *)s
; n
>=SS
&& !HASZERO(*w
^k
); w
++, n
-=SS
);
20 for (s
= (const void *)w
; n
&& *s
!= c
; s
++, n
--);
22 return n
? (void *)s
: 0;