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.

60 lines
1.4 KiB

  1. /***
  2. *strrchr.c - find last occurrence of character in string
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines strrchr() - find the last occurrence of a given character
  8. * in a string.
  9. *
  10. *Revision History:
  11. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  12. * copyright.
  13. * 08-14-90 SBM Compiles cleanly with -W3, removed now redundant
  14. * #include <stddef.h>
  15. * 10-02-90 GJF New-style function declarator.
  16. * 09-03-93 GJF Replaced _CALLTYPE1 with __cdecl.
  17. *
  18. *******************************************************************************/
  19. #include <cruntime.h>
  20. #include <string.h>
  21. /***
  22. *char *strrchr(string, ch) - find last occurrence of ch in string
  23. *
  24. *Purpose:
  25. * Finds the last occurrence of ch in string. The terminating
  26. * null character is used as part of the search.
  27. *
  28. *Entry:
  29. * char *string - string to search in
  30. * char ch - character to search for
  31. *
  32. *Exit:
  33. * returns a pointer to the last occurrence of ch in the given
  34. * string
  35. * returns NULL if ch does not occurr in the string
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40. char * __cdecl strrchr (
  41. const char * string,
  42. int ch
  43. )
  44. {
  45. char *start = (char *)string;
  46. while (*string++) /* find end of string */
  47. ;
  48. /* search towards front */
  49. while (--string != start && *string != (char)ch)
  50. ;
  51. if (*string == (char)ch) /* char found ? */
  52. return( (char *)string );
  53. return(NULL);
  54. }