home *** CD-ROM | disk | FTP | other *** search
/ Atari FTP / ATARI_FTP_0693.zip / ATARI_FTP_0693 / Mint / mntlib25.zoo / strstr.c < prev    next >
C/C++ Source or Header  |  1992-09-17  |  668b  |  29 lines

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