replace.cpp 490 B

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