[PATCH] Add simplistic compat implementation for strcasestr
authorDirk Hohndel <hohndel@x200.gr8dns.org>
Tue, 13 Apr 2010 16:17:37 +0000 (09:17 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:36:37 +0000 (09:36 -0800)
c2/9d19fda2402ad6296ea586d229b15a5f41d669 [new file with mode: 0644]

diff --git a/c2/9d19fda2402ad6296ea586d229b15a5f41d669 b/c2/9d19fda2402ad6296ea586d229b15a5f41d669
new file mode 100644 (file)
index 0000000..04e9a66
--- /dev/null
@@ -0,0 +1,133 @@
+Return-Path: <hohndel@x200.gr8dns.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 017534196F2\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 09:50:19 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.401\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.401 tagged_above=-999 required=5\r
+       tests=[BAYES_05=-0.5, DKIM_ADSP_NXDOMAIN=0.9, NO_DNS_FOR_FROM=0.001]\r
+       autolearn=no\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 FDltHHGo+idq for <notmuch@notmuchmail.org>;\r
+       Tue, 13 Apr 2010 09:50:18 -0700 (PDT)\r
+Received: from mail.hohndel.org (mail.hohndel.org [65.23.157.147])\r
+       by olra.theworths.org (Postfix) with ESMTP id 5EBD9431FC1\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 09:50:18 -0700 (PDT)\r
+Received: by mail.hohndel.org (Postfix, from userid 112)\r
+       id 9E326340FC; Tue, 13 Apr 2010 12:17:40 -0400 (EDT)\r
+Received: from x200.gr8dns.org (unknown [65.23.157.147])\r
+       by mail.hohndel.org (Postfix) with ESMTP id 84243340F8\r
+       for <notmuch@notmuchmail.org>; Tue, 13 Apr 2010 12:17:38 -0400 (EDT)\r
+Received: by x200.gr8dns.org (Postfix, from userid 500)\r
+       id 58358C00E5; Tue, 13 Apr 2010 09:17:37 -0700 (PDT)\r
+From: Dirk Hohndel <hohndel@x200.gr8dns.org>\r
+To: <notmuch@notmuchmail.org>\r
+Subject: [PATCH] Add simplistic compat implementation for strcasestr\r
+Date: Tue, 13 Apr 2010 09:17:37 -0700\r
+Message-ID: <m339yzcony.fsf@x200.gr8dns.org>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain; charset=us-ascii\r
+X-Mailman-Approved-At: Tue, 13 Apr 2010 11:39:58 -0700\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 16:50:19 -0000\r
+\r
+\r
+v.2 of the patch, this time including the Makefile logic.\r
+All platforms I have access to support strcasestr - so please test\r
+that the implementation / integration works correctly on those\r
+plattforms.\r
+\r
+Signed-off-by: Dirk Hohndel <hohndel@infradead.org>\r
+---\r
+ compat/have_strcasestr.c |   10 ++++++++++\r
+ compat/strcasestr.c      |   41 +++++++++++++++++++++++++++++++++++++++++\r
+ 2 files changed, 51 insertions(+), 0 deletions(-)\r
+ create mode 100644 compat/have_strcasestr.c\r
+ create mode 100644 compat/strcasestr.c\r
+\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
+-- \r
+1.6.6.1\r
+\r
+\r
+-- \r
+Dirk Hohndel\r
+Intel Open Source Technology Center\r