7 #define SS (sizeof(size_t)) 8 #define ALIGN (sizeof(size_t) - 1) 9 #define ONES ((size_t)-1 / UCHAR_MAX) 10 #define HIGHS (ONES * (UCHAR_MAX / 2 + 1)) 11 #define HASZERO(x) ((x)-ONES & ~(x)&HIGHS) 13 void*
memchr(
const void* src,
int c,
size_t n)
15 const unsigned char* s = src;
19 for(; ((uintptr_t)s &
ALIGN) && n && *s != c; s++, n--)
27 size_t k =
ONES * (size_t)c;
29 for(w = (
const void*)s; n >=
SS && !
HASZERO(*w ^ k); w++, n -=
SS)
37 for(; n && *s != c; s++, n--)
41 return n ? (
void*)(uintptr_t)s : 0;
__attribute__((noreturn, weak)) void __assert_fail(const char *expr
void * memchr(const void *src, int c, size_t n)
Finds the first occurrence of c in the initial n characters of the object pointed to by s.