UPS: apcupsd clean sources
[tomato.git] / release / src / router / apcupsd / src / lib / strstr.c
blob5b80fe430a2531a1c558589c077dfb000d52e067
1 /*
2 * strstr.c -- return the offset of one string within another.
4 * Copyright (C) 1997 Free Software Foundation, Inc.
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.
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.
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.
21 /* Written by Philippe De Muyter <phdm@info.ucl.ac.be>. */
24 * NAME
26 * strstr -- locate first occurence of a substring
28 * SYNOPSIS
30 * char *strstr (char *s1, char *s2)
32 * DESCRIPTION
34 * Locates the first occurence 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.
39 * BUGS
43 char *
44 strstr (buf, sub)
45 register char *buf;
46 register char *sub;
48 register char *bp;
50 if (!*sub)
51 return buf;
52 for (;;)
54 if (!*buf)
55 break;
56 bp = buf;
57 for (;;)
59 if (!*sub)
60 return buf;
61 if (*bp++ != *sub++)
62 break;
64 sub -= (unsigned long) bp;
65 sub += (unsigned long) buf;
66 buf += 1;
68 return 0;