Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // File: wcsrchr.c
  4. //
  5. // Contents: This file contains the src for the wcsrchr() function.
  6. //
  7. // Classes: none
  8. //
  9. // History: 09-Oct-91 chrismay created
  10. //
  11. //----------------------------------------------------------------------------
  12. #include <stddef.h>
  13. #include <stdlib.h>
  14. //+---------------------------------------------------------------------------
  15. //
  16. // Function: wcsrchr()
  17. //
  18. // Synopsis: This function finds the last occurrence of the specified wide
  19. // character in a wide-character string.
  20. //
  21. // Arguments: wsz - wide character string, zero terminated
  22. // wc - wide character to be found in wsz
  23. //
  24. // Returns: returns a pointer to the beginning of the substring that
  25. // begins with the last occurrence of the character if found,
  26. // else returns NULL.
  27. //
  28. // Warnings: only works on wide-character ASCII
  29. //
  30. // History: 15-Oct-91 chrismay created
  31. //
  32. //----------------------------------------------------------------------------
  33. wchar_t *__cdecl wcsrchr(const wchar_t *wcs, wchar_t wc)
  34. {
  35. wchar_t *start = (wchar_t *)wcs;
  36. while (*wcs++) /* find end of string */
  37. ;
  38. /* search towards front */
  39. while (--wcs != start && *wcs != wc)
  40. ;
  41. if (*wcs == wc) /* character found ? */
  42. return (wchar_t *)wcs;
  43. return NULL;
  44. }