]> git.cworth.org Git - notmuch/blob - compat/strcasestr.c
emacs: Add new option notmuch-search-hide-excluded
[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 *
28 strcasestr (const char *haystack, const char *needle)
29 {
30     size_t hay_len = strlen (haystack);
31     size_t needle_len = strlen (needle);
32
33     while (hay_len >= needle_len) {
34         if (strncasecmp (haystack, needle, needle_len) == 0)
35             return (char *) haystack;
36
37         haystack++;
38         hay_len--;
39     }
40
41     return NULL;
42 }