home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 6 / FreshFish_September1994.bin / bbs / gnu / pdksh-4.9-src.lha / GNU / src / amiga / pdksh-4.9 / std / stdc / strstr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-04  |  686 b   |  32 lines

  1. #ifndef lint
  2. static char *RCSid = "$Id: strstr.c,v 1.3 93/05/05 21:18:56 sjg Exp $";
  3. #endif
  4.  
  5. #include "stdh.h"
  6.  
  7. /*
  8.  * strstr - find first occurrence of wanted in s
  9.  */
  10.  
  11. char *                /* found string, or NULL if none */
  12. strstr(s, wanted)
  13. const char *s;
  14. const char *wanted;
  15. {
  16.     register const char *scan;
  17.     register size_t len;
  18.     register char firstc;
  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.