1
0

strrstr.c 785 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. ** Copyright 1998-2002 University of Illinois Board of Trustees
  3. ** Copyright 1998-2002 Mark D. Roth
  4. ** All rights reserved.
  5. **
  6. ** strrstr.c - strrstr() function for compatibility library
  7. **
  8. ** Mark D. Roth <[email protected]>
  9. ** Campus Information Technologies and Educational Services
  10. ** University of Illinois at Urbana-Champaign
  11. */
  12. #include <stdio.h>
  13. #include <sys/types.h>
  14. #include <string.h>
  15. /*
  16. ** find the last occurrance of find in string
  17. */
  18. char *
  19. strrstr(char *string, char *find)
  20. {
  21. size_t stringlen, findlen;
  22. char *cp;
  23. findlen = strlen(find);
  24. stringlen = strlen(string);
  25. if (findlen > stringlen)
  26. return NULL;
  27. for (cp = string + stringlen - findlen; cp >= string; cp--)
  28. if (strncmp(cp, find, findlen) == 0)
  29. return cp;
  30. return NULL;
  31. }