| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "build-defs.h" | ||
| 2 | #include <string.h> | ||
| 3 | #include "xmemrchr.h" | ||
| 4 | |||
| 5 | 447 | void *xmemrchr(const void *ptr, int c, size_t n) | |
| 6 | { | ||
| 7 | #if HAVE_MEMRCHR | ||
| 8 | // See also: the comment at the top of src/util/xstring.h | ||
| 9 |
2/2✓ Branch 2 → 3 taken 440 times.
✓ Branch 2 → 4 taken 7 times.
|
447 | return likely(n) ? memrchr(ptr, c, n) : NULL; |
| 10 | #endif | ||
| 11 | |||
| 12 | for (const unsigned char *s = ptr; n--; ) { | ||
| 13 | if (s[n] == (unsigned char)c) { | ||
| 14 | return (void*)(s + n); | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | return NULL; | ||
| 19 | } | ||
| 20 |