Line data Source code
1 : /* 2 : replacement functions for systems that are missing required library functions 3 : */ 4 : 5 : #include "replace.h" 6 : 7 : #ifndef HAVE_MEMRCHR 8 : /* 9 : replacement for memrchr(). Note that we make the buffer non-const to 10 : avoid issues with converting const to non-const 11 : */ 12 18 : void *replace_memrchr(void *s, int c, size_t n) 13 : { 14 18 : uint8_t *b = (uint8_t *)s; 15 58 : for (int32_t i=n-1; i>=0; i--) { 16 52 : if (b[i] == (uint8_t)c) { 17 12 : return (void *)&b[i]; 18 : } 19 : } 20 6 : return nullptr; 21 : } 22 : #endif