memrchr.c 518 B

12345678910111213141516171819202122232425262728
  1. /*
  2. * Copyright (C) 2002 Manuel Novoa III
  3. * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
  4. *
  5. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  6. */
  7. #include "_string.h"
  8. #ifdef __USE_GNU
  9. void *memrchr(const void *s, int c, size_t n)
  10. {
  11. register const unsigned char *r;
  12. r = ((unsigned char *)s) + ((size_t) n);
  13. while (n) {
  14. if (*--r == ((unsigned char)c)) {
  15. return (void *) r; /* silence the warning */
  16. }
  17. --n;
  18. }
  19. return NULL;
  20. }
  21. libc_hidden_def(memrchr)
  22. #endif