memchr.c 742 B

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