memchr.c 729 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. # undef memchr
  12. # define Wmemchr memchr
  13. #endif
  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)