home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / Linux / Divers / lynx2.8.1dev.10.tar.gz / lynx2.8.1dev.10.tar / lynx2-8 / src / strstr.c < prev    next >
Text File  |  1997-11-23  |  2KB  |  65 lines

  1. /*
  2.  * strstr.c -- return the offset of one string within another.
  3.  *
  4.  * Copyright (C) 1997 Free Software Foundation, Inc.
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify it under
  7.  * the terms of the GNU General Public License as published by the Free
  8.  * Software Foundation; either version 2, or (at your option) any later
  9.  * version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful, but WITHOUT
  12.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13.  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
  14.  * more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License along with
  17.  * this program; if not, write to the Free Software Foundation, Inc., 59
  18.  * Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19.  */
  20.  
  21. /* Written by Philippe De Muyter <phdm@macqel.be>.  */
  22.  
  23. /*
  24.  * NAME
  25.  *
  26.  * strstr -- locate first occurrence of a substring
  27.  *
  28.  * SYNOPSIS
  29.  *
  30.  * char *strstr (char *s1, char *s2)
  31.  *
  32.  * DESCRIPTION
  33.  *
  34.  * Locates the first occurrence in the string pointed to by S1 of the string
  35.  * pointed to by S2.  Returns a pointer to the substring found, or a NULL
  36.  * pointer if not found.  If S2 points to a string with zero length, the
  37.  * function returns S1.
  38.  *
  39.  * BUGS
  40.  *
  41.  */
  42.  
  43. char *
  44. strstr (buf, sub)
  45.      register char *buf;
  46.      register char *sub;
  47. {
  48.   register char *bp;
  49.   register char *sp;
  50.  
  51.   if (!*sub)
  52.     return buf;
  53.   while (*buf)
  54.     {
  55.       bp = buf;
  56.       sp = sub;
  57.       do {
  58.           if (!*sp)
  59.             return buf;
  60.       } while (*bp++ == *sp++);
  61.       buf += 1;
  62.     }
  63.   return 0;
  64. }
  65.