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