]> diplodocus.org Git - nmh/blob - sbr/ssequal.c
9cca3d6f509c69b7f85c168a3b3538268f782f4d
[nmh] / sbr / ssequal.c
1 /*
2 * ssequal.c -- check if a string is a substring of another
3 *
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
7 */
8
9 #include <h/mh.h>
10
11 /*
12 * THIS CODE DOES NOT WORK AS ADVERTISED.
13 * It is actually checking if s1 is a PREFIX of s2.
14 * All calls to this function need to be checked to see
15 * if that needs to be changed. Prefix checking is cheaper, so
16 * should be kept if it's sufficient.
17 */
18
19 /*
20 * Check if s1 is a substring of s2.
21 * If yes, then return 1, else return 0.
22 */
23
24 int
25 ssequal (const char *s1, const char *s2)
26 {
27 if (!s1)
28 s1 = "";
29 if (!s2)
30 s2 = "";
31
32 while (*s1)
33 if (*s1++ != *s2++)
34 return 0;
35 return 1;
36 }