]> git.notmuchmail.org Git - notmuch/blob - compat/strcasestr.c
debian: changelog for 0.29.3
[notmuch] / compat / strcasestr.c
1 /*
2  * slow simplistic reimplementation of strcasestr for systems that
3  * don't include it in their library
4  *
5  * based on a GPL implementation in OpenTTD found under GPL v2
6
7    This program is free software; you can redistribute it and/or
8    modify it under the terms of the GNU General Public License as
9    published by the Free Software Foundation, version 2.
10
11    This program is distributed in the hope that it will be useful, but
12    WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14    General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program; if not, write to the Free Software
18    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19    02110-1301, USA.  */
20
21 /* Imported into notmuch by Dirk Hohndel - original author unknown. */
22
23 #include <string.h>
24
25 #include "compat.h"
26
27 char *strcasestr(const char *haystack, const char *needle)
28 {
29         size_t hay_len = strlen(haystack);
30         size_t needle_len = strlen(needle);
31         while (hay_len >= needle_len) {
32                 if (strncasecmp(haystack, needle, needle_len) == 0)
33                     return (char *) haystack;
34
35                 haystack++;
36                 hay_len--;
37         }
38
39         return NULL;
40 }