home *** CD-ROM | disk | FTP | other *** search
/ Borland Programmer's Resource / Borland_Programmers_Resource_CD_1995.iso / utils / source / sh / std / stdc / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-05-19  |  595 b   |  28 lines

  1. #include <string.h>
  2.  
  3. /*
  4.  * strstr - find first occurrence of wanted in s
  5.  */
  6.  
  7. char *                /* found string, or NULL if none */
  8. strstr(s, wanted)
  9. Const char *s;
  10. Const char *wanted;
  11. {
  12.     register Const char *scan;
  13.     register size_t len;
  14.     register char firstc;
  15.  
  16.     /*
  17.      * The odd placement of the two tests is so "" is findable.
  18.      * Also, we inline the first char for speed.
  19.      * The ++ on scan has been moved down for optimization.
  20.      */
  21.     firstc = *wanted;
  22.     len = strlen(wanted);
  23.     for (scan = s; *scan != firstc || strncmp(scan, wanted, len) != 0; )
  24.         if (*scan++ == '\0')
  25.             return(NULL);
  26.     return(scan);
  27. }
  28.