~ubuntu-branches/ubuntu/warty/lynx/warty-security

« back to all changes in this revision

Viewing changes to src/strstr.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2004-09-16 12:14:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040916121410-cz1gu92c4nqfeyrg
Tags: upstream-2.8.5
ImportĀ upstreamĀ versionĀ 2.8.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}