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