home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / pdc / libsrc / stringlib / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-07  |  656 b   |  32 lines

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