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