memrchr.c 690 B

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