[PATCH] Add simplistic reimplementation of strcasestr to compat library
authorDirk Hohndel <hohndel@infradead.org>
Tue, 13 Apr 2010 04:10:31 +0000 (21:10 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:36 +0000 (09:36 -0800)
e6/21737910a1017cb9e3b4ee3dc7cd3a86e3f619 [new file with mode: 0644]

diff --git a/e6/21737910a1017cb9e3b4ee3dc7cd3a86e3f619 b/e6/21737910a1017cb9e3b4ee3dc7cd3a86e3f619
new file mode 100644 (file)
index 0000000..54d112b
--- /dev/null
@@ -0,0 +1,180 @@
+Return-Path: <BATV+47682ed40cd14f842012+2424+infradead.org+hohndel@bombadil.srs.infradead.org>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+       by olra.theworths.org (Postfix) with ESMTP id 4F723418C34\r
+       for <notmuch@notmuchmail.org>; Mon, 12 Apr 2010 21:10:57 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: -4.2\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=-4.2 tagged_above=-999 required=5\r
+       tests=[BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3] autolearn=ham\r
+Received: from olra.theworths.org ([127.0.0.1])\r
+       by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
+       with ESMTP id UAAeXN388vNH for <notmuch@notmuchmail.org>;\r
+       Mon, 12 Apr 2010 21:10:56 -0700 (PDT)\r
+Received: from bombadil.infradead.org (bombadil.infradead.org [18.85.46.34])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5DD53431FC1\r
+       for <notmuch@notmuchmail.org>; Mon, 12 Apr 2010 21:10:56 -0700 (PDT)\r
+Received: from localhost ([::1] helo=x200.gr8dns.org)\r
+       by bombadil.infradead.org with esmtp (Exim 4.69 #1 (Red Hat Linux))\r
+       id 1O1XSh-0006Kc-CJ\r
+       for notmuch@notmuchmail.org; Tue, 13 Apr 2010 04:10:56 +0000\r
+Received: by x200.gr8dns.org (Postfix, from userid 500)\r
+       id 06D40C00E1; Mon, 12 Apr 2010 21:10:32 -0700 (PDT)\r
+From: Dirk Hohndel <hohndel@infradead.org>\r
+To: <notmuch@notmuchmail.org>\r
+Subject: [PATCH] Add simplistic reimplementation of strcasestr to compat\r
+       library\r
+Date: Mon, 12 Apr 2010 21:10:31 -0700\r
+Message-ID: <m3eiikc7rc.fsf@x200.gr8dns.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-SRS-Rewrite: SMTP reverse-path rewritten from <hohndel@infradead.org> by\r
+       bombadil.infradead.org See http://www.infradead.org/rpr.html\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.13\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+       <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+       <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 13 Apr 2010 04:10:57 -0000\r
+\r
+\r
+While all systems that I have access to support strcasestr, it is\r
+in fact not part of POSIX. So here's a fallback reimplementation\r
+based on POSIX functions.\r
+\r
+Signed-off-by: Dirk Hohndel <hohndel@infradead.org>\r
+---\r
+ compat/Makefile.local    |    4 ++++\r
+ compat/have_strcasestr.c |   10 ++++++++++\r
+ compat/strcasestr.c      |   41 +++++++++++++++++++++++++++++++++++++++++\r
+ configure                |   15 +++++++++++++++\r
+ 4 files changed, 70 insertions(+), 0 deletions(-)\r
+ create mode 100644 compat/have_strcasestr.c\r
+ create mode 100644 compat/strcasestr.c\r
+\r
+diff --git a/compat/Makefile.local b/compat/Makefile.local\r
+index 81e6c70..2a52a14 100644\r
+--- a/compat/Makefile.local\r
++++ b/compat/Makefile.local\r
+@@ -8,3 +8,7 @@ notmuch_compat_srcs =\r
+ ifneq ($(HAVE_GETLINE),1)\r
+ notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c\r
+ endif\r
++\r
++ifneq ($(HAVE_STRCASESTR),1)\r
++notmuch_compat_srcs += $(dir)/strcasestr.c \r
++endif\r
+\ No newline at end of file\r
+diff --git a/compat/have_strcasestr.c b/compat/have_strcasestr.c\r
+new file mode 100644\r
+index 0000000..c0fb762\r
+--- /dev/null\r
++++ b/compat/have_strcasestr.c\r
+@@ -0,0 +1,10 @@\r
++#define _GNU_SOURCE\r
++#include <strings.h>\r
++\r
++int main()\r
++{\r
++    char *found;\r
++    const char *haystack, *needle;\r
++\r
++    found = strcasestr(haystack, needle);\r
++}\r
+diff --git a/compat/strcasestr.c b/compat/strcasestr.c\r
+new file mode 100644\r
+index 0000000..50bc89d\r
+--- /dev/null\r
++++ b/compat/strcasestr.c\r
+@@ -0,0 +1,41 @@\r
++/*\r
++ * slow simplistic reimplementation of strcasestr for systems that\r
++ * don't include it in their library\r
++ *\r
++ * based on a GPL implementation in OpenTTD found under GPL v2\r
++\r
++   This program is free software; you can redistribute it and/or\r
++   modify it under the terms of the GNU General Public License as\r
++   published by the Free Software Foundation, version 2.\r
++\r
++   This program is distributed in the hope that it will be useful, but\r
++   WITHOUT ANY WARRANTY; without even the implied warranty of\r
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++   General Public License for more details.\r
++\r
++   You should have received a copy of the GNU General Public License\r
++   along with this program; if not, write to the Free Software\r
++   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA\r
++   02110-1301, USA.  */\r
++\r
++/* Imported into notmuch by Dirk Hohndel - original author unknown. */\r
++/* the semantic here actually puzzles me:\r
++   how can haystack be const char * - yet the return value is char *\r
++   after all, it points to a sub-string of haystack... */\r
++\r
++#include <string.h>\r
++\r
++char *strcasestr(const char *haystack, const char *needle)\r
++{\r
++      size_t hay_len = strlen(haystack);\r
++      size_t needle_len = strlen(needle);\r
++      while (hay_len >= needle_len) {\r
++              if (strncasecmp(haystack, needle, needle_len) == 0) \r
++                  return (char *) haystack;\r
++\r
++              haystack++;\r
++              hay_len--;\r
++      }\r
++\r
++      return NULL;\r
++}\r
+diff --git a/configure b/configure\r
+index 5af7852..023aa40 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -310,6 +310,17 @@ else\r
+ fi\r
+ rm -f compat/have_getline\r
\r
++printf "Checking for strcasestr... "\r
++if ${CC} -o compat/have_strcasestr compat/have_strcasestr.c > /dev/null 2>&1\r
++then\r
++    printf "Yes.\n"\r
++    have_strcasestr=1\r
++else\r
++    printf "No (will use our own instead).\n"\r
++    have_strcasestr=0\r
++fi\r
++rm -f compat/have_strcasestr\r
++\r
+ cat <<EOF\r
\r
+ All required packages were found. You may now run the following\r
+@@ -384,6 +395,10 @@ zsh_completion_dir = \$(prefix)/share/zsh/functions/Completion/Unix\r
+ # build its own version)\r
+ HAVE_GETLINE = ${have_getline}\r
\r
++# Whether the strcasestr function is available (if not, then notmuch will\r
++# build its own version)\r
++HAVE_STRCASESTR = ${have_strcasestr}\r
++\r
+ # Flags needed to compile and link against Xapian\r
+ XAPIAN_CXXFLAGS = ${xapian_cxxflags}\r
+ XAPIAN_LDFLAGS = ${xapian_ldflags}\r
+-- \r
+1.6.6.1\r
+\r
+\r
+-- \r
+Dirk Hohndel\r
+Intel Open Source Technology Center\r