memrchr.c 344 B

123456789101112131415161718192021222324
  1. /*
  2. * Copyright (c) 2019, Arm Limited. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #include <string.h>
  7. #undef memrchr
  8. void *memrchr(const void *src, int c, size_t len)
  9. {
  10. const unsigned char *s = src + (len - 1);
  11. while (len--) {
  12. if (*s == (unsigned char)c) {
  13. return (void*) s;
  14. }
  15. s--;
  16. }
  17. return NULL;
  18. }