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.

62 lines
1.5 KiB

  1. /***
  2. *wcsrchr.c - find last occurrence of wchar_t character in wide string
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines wcsrchr() - find the last occurrence of a given character
  8. * in a string (wide-characters).
  9. *
  10. *Revision History:
  11. * 09-09-91 ETC Created from strrchr.c.
  12. * 04-07-92 KRS Updated and ripped out _INTL switches.
  13. * 04-06-93 SKS Replace _CRTAPI* with __cdecl
  14. * 02-07-94 CFW POSIXify.
  15. *
  16. *******************************************************************************/
  17. #ifndef _POSIX_
  18. #include <cruntime.h>
  19. #include <string.h>
  20. /***
  21. *wchar_t *wcsrchr(string, ch) - find last occurrence of ch in wide string
  22. *
  23. *Purpose:
  24. * Finds the last occurrence of ch in string. The terminating
  25. * null character is used as part of the search (wide-characters).
  26. *
  27. *Entry:
  28. * wchar_t *string - string to search in
  29. * wchar_t ch - character to search for
  30. *
  31. *Exit:
  32. * returns a pointer to the last occurrence of ch in the given
  33. * string
  34. * returns NULL if ch does not occurr in the string
  35. *
  36. *Exceptions:
  37. *
  38. *******************************************************************************/
  39. wchar_t * __cdecl wcsrchr (
  40. const wchar_t * string,
  41. wchar_t ch
  42. )
  43. {
  44. wchar_t *start = (wchar_t *)string;
  45. while (*string++) /* find end of string */
  46. ;
  47. /* search towards front */
  48. while (--string != start && *string != (wchar_t)ch)
  49. ;
  50. if (*string == (wchar_t)ch) /* wchar_t found ? */
  51. return( (wchar_t *)string );
  52. return(NULL);
  53. }
  54. #endif /* _POSIX_ */