Leaked source code of windows server 2003
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.

70 lines
1.5 KiB

  1. /***
  2. *strstr.c - search for one string inside another
  3. *
  4. * Copyright (c) 1985-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * defines strstr() - search for one string inside another
  8. *
  9. *Revision History:
  10. * 02-27-90 GJF Fixed calling type, #include <cruntime.h>, fixed
  11. * copyright.
  12. * 08-14-90 SBM Removed now redundant #include <stddef.h>
  13. * 10-02-90 GJF New-style function declarator.
  14. * 09-03-93 GJF Replaced _CALLTYPE1 with __cdecl.
  15. * 03-14-94 GJF If string2 is empty, return string1.
  16. * 12-30-94 CFW Avoid 'const' warning.
  17. *
  18. *******************************************************************************/
  19. #include <cruntime.h>
  20. #include <string.h>
  21. /***
  22. *char *strstr(string1, string2) - search for string2 in string1
  23. *
  24. *Purpose:
  25. * finds the first occurrence of string2 in string1
  26. *
  27. *Entry:
  28. * char *string1 - string to search in
  29. * char *string2 - string to search for
  30. *
  31. *Exit:
  32. * returns a pointer to the first occurrence of string2 in
  33. * string1, or NULL if string2 does not occur in string1
  34. *
  35. *Uses:
  36. *
  37. *Exceptions:
  38. *
  39. *******************************************************************************/
  40. char * __cdecl strstr (
  41. const char * str1,
  42. const char * str2
  43. )
  44. {
  45. char *cp = (char *) str1;
  46. char *s1, *s2;
  47. if ( !*str2 )
  48. return((char *)str1);
  49. while (*cp)
  50. {
  51. s1 = cp;
  52. s2 = (char *) str2;
  53. while ( *s1 && *s2 && !(*s1-*s2) )
  54. s1++, s2++;
  55. if (!*s2)
  56. return(cp);
  57. cp++;
  58. }
  59. return(NULL);
  60. }