wcschr.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* Copyright (C) 1995-2026 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, see
  13. <https://www.gnu.org/licenses/>. */
  14. #include <wchar.h>
  15. #include <loop_unroll.h>
  16. #ifndef WCSCHR
  17. # define WCSCHR __wcschr
  18. #endif
  19. /* Find the first occurrence of WC in WCS. */
  20. wchar_t *
  21. WCSCHR (const wchar_t *wcs, const wchar_t wc)
  22. {
  23. wchar_t *dest = NULL;
  24. #define ITERATION(index) \
  25. ({ \
  26. if (*wcs == wc) \
  27. dest = (wchar_t*) wcs; \
  28. dest == NULL && *wcs++ != L'\0'; \
  29. })
  30. #ifndef UNROLL_NTIMES
  31. # define UNROLL_NTIMES 1
  32. #endif
  33. while (1)
  34. UNROLL_REPEAT (UNROLL_NTIMES, ITERATION);
  35. return dest;
  36. }
  37. libc_hidden_def (__wcschr)
  38. static_weak_alias (__wcschr, wcschr)
  39. libc_hidden_weak (wcschr)