memrchr.c 688 B

123456789101112131415161718192021222324252627282930313233
  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. void attribute_hidden *__memrchr(const void *s, int c, size_t n)
  9. {
  10. register const unsigned char *r;
  11. #ifdef __BCC__
  12. /* bcc can optimize the counter if it thinks it is a pointer... */
  13. register const char *np = (const char *) n;
  14. #else
  15. #define np n
  16. #endif
  17. r = ((unsigned char *)s) + ((size_t) np);
  18. while (np) {
  19. if (*--r == ((unsigned char)c)) {
  20. return (void *) r; /* silence the warning */
  21. }
  22. --np;
  23. }
  24. return NULL;
  25. }
  26. #undef np
  27. strong_alias(__memrchr,memrchr)