memrchr.c 741 B

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