[PATCH 06/10] strsep: check for availability (Solaris support)
authorBlake Jones <blakej@foo.net>
Sun, 4 Nov 2012 03:15:58 +0000 (20:15 +1700)
committerW. Trevor King <wking@tremily.us>
Fri, 7 Nov 2014 17:50:17 +0000 (09:50 -0800)
a3/f7f01eaa1851567cc2dd59b587f7f49605ac4b [new file with mode: 0644]

diff --git a/a3/f7f01eaa1851567cc2dd59b587f7f49605ac4b b/a3/f7f01eaa1851567cc2dd59b587f7f49605ac4b
new file mode 100644 (file)
index 0000000..a2c07d2
--- /dev/null
@@ -0,0 +1,234 @@
+Return-Path: <blakej@foo.net>\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 ECF8D431FD4\r
+       for <notmuch@notmuchmail.org>; Sat,  3 Nov 2012 20:24:25 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
+       autolearn=disabled\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 HCvaLNsSpd7C for <notmuch@notmuchmail.org>;\r
+       Sat,  3 Nov 2012 20:24:24 -0700 (PDT)\r
+Received: from foo.net (70-36-235-136.dsl.static.sonic.net [70.36.235.136])\r
+       (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
+       (No client certificate requested)\r
+       by olra.theworths.org (Postfix) with ESMTPS id 268D0431FD0\r
+       for <notmuch@notmuchmail.org>; Sat,  3 Nov 2012 20:24:21 -0700 (PDT)\r
+Received: from foo.net (localhost [127.0.0.1])\r
+       by foo.net (8.14.5+Sun/8.14.5) with ESMTP id qA43GGPn025686;\r
+       Sat, 3 Nov 2012 20:16:16 -0700 (PDT)\r
+Received: (from blakej@localhost)\r
+       by foo.net (8.14.5+Sun/8.14.5/Submit) id qA43GG40025685;\r
+       Sat, 3 Nov 2012 20:16:16 -0700 (PDT)\r
+From: Blake Jones <blakej@foo.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 06/10] strsep: check for availability (Solaris support)\r
+Date: Sat,  3 Nov 2012 20:15:58 -0700\r
+Message-Id: <1351998962-25135-7-git-send-email-blakej@foo.net>\r
+X-Mailer: git-send-email 1.7.3.2\r
+In-Reply-To: <1351998962-25135-1-git-send-email-blakej@foo.net>\r
+References: <1351998962-25135-1-git-send-email-blakej@foo.net>\r
+X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2\r
+       (foo.net [127.0.0.1]); Sat, 03 Nov 2012 20:16:16 -0700 (PDT)\r
+X-Mailman-Approved-At: Sun, 04 Nov 2012 01:30:19 -0800\r
+Cc: Blake Jones <blakej@foo.net>\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: Sun, 04 Nov 2012 03:24:26 -0000\r
+\r
+Solaris does not ship a version of the strsep() function.  This change\r
+adds a check to "configure" to see whether notmuch needs to provide its\r
+own implementation, and if so, it uses the new version in\r
+"compat/strsep.c" (which was copied from Mutt, and apparently before\r
+that from glibc).\r
+---\r
+ compat/Makefile.local |    4 +++\r
+ compat/compat.h       |    4 +++\r
+ compat/have_strsep.c  |   10 ++++++++\r
+ compat/strsep.c       |   65 +++++++++++++++++++++++++++++++++++++++++++++++++\r
+ configure             |   17 +++++++++++++\r
+ 5 files changed, 100 insertions(+)\r
+ create mode 100644 compat/have_strsep.c\r
+ create mode 100644 compat/strsep.c\r
+\r
+diff --git a/compat/Makefile.local b/compat/Makefile.local\r
+index 13f16cd..2c4f65f 100644\r
+--- a/compat/Makefile.local\r
++++ b/compat/Makefile.local\r
+@@ -13,4 +13,8 @@ ifneq ($(HAVE_STRCASESTR),1)\r
+ notmuch_compat_srcs += $(dir)/strcasestr.c\r
+ endif\r
\r
++ifneq ($(HAVE_STRSEP),1)\r
++notmuch_compat_srcs += $(dir)/strsep.c\r
++endif\r
++\r
+ SRCS := $(SRCS) $(notmuch_compat_srcs)\r
+diff --git a/compat/compat.h b/compat/compat.h\r
+index b750501..1fd2723 100644\r
+--- a/compat/compat.h\r
++++ b/compat/compat.h\r
+@@ -46,6 +46,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);\r
+ char* strcasestr(const char *haystack, const char *needle);\r
+ #endif /* !HAVE_STRCASESTR */\r
\r
++#if !HAVE_STRSEP\r
++char *strsep(char **stringp, const char *delim);\r
++#endif /* !HAVE_STRSEP */\r
++\r
+ /* Silence gcc warnings about unused results.  These warnings exist\r
+  * for a reason; any use of this needs to be justified. */\r
+ #ifdef __GNUC__\r
+diff --git a/compat/have_strsep.c b/compat/have_strsep.c\r
+new file mode 100644\r
+index 0000000..5bd396c\r
+--- /dev/null\r
++++ b/compat/have_strsep.c\r
+@@ -0,0 +1,10 @@\r
++#define _GNU_SOURCE\r
++#include <string.h>\r
++\r
++int main()\r
++{\r
++    char *found;\r
++    char **stringp, const char *delim;\r
++\r
++    found = strsep(stringp, delim);\r
++}\r
+diff --git a/compat/strsep.c b/compat/strsep.c\r
+new file mode 100644\r
+index 0000000..78ab9e7\r
+--- /dev/null\r
++++ b/compat/strsep.c\r
+@@ -0,0 +1,65 @@\r
++/* Copyright (C) 1992, 93, 96, 97, 98, 99, 2004 Free Software Foundation, Inc.\r
++   This file is part of the GNU C Library.\r
++\r
++   The GNU C Library is free software; you can redistribute it and/or\r
++   modify it under the terms of the GNU Lesser General Public\r
++   License as published by the Free Software Foundation; either\r
++   version 2.1 of the License, or (at your option) any later version.\r
++\r
++   The GNU C Library is distributed in the hope that it will be useful,\r
++   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
++   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
++   Lesser General Public License for more details.\r
++\r
++   You should have received a copy of the GNU Lesser General Public\r
++   License along with the GNU C Library; if not, write to the Free\r
++   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
++   02111-1307 USA.  */\r
++\r
++#include <string.h>\r
++\r
++/* Taken from glibc 2.6.1 */\r
++\r
++char *strsep (char **stringp, const char *delim)\r
++{\r
++  char *begin, *end;\r
++\r
++  begin = *stringp;\r
++  if (begin == NULL)\r
++    return NULL;\r
++\r
++  /* A frequent case is when the delimiter string contains only one\r
++     character.  Here we don't need to call the expensive `strpbrk'\r
++     function and instead work using `strchr'.  */\r
++  if (delim[0] == '\0' || delim[1] == '\0')\r
++    {\r
++      char ch = delim[0];\r
++\r
++      if (ch == '\0')\r
++      end = NULL;\r
++      else\r
++      {\r
++        if (*begin == ch)\r
++          end = begin;\r
++        else if (*begin == '\0')\r
++          end = NULL;\r
++        else\r
++          end = strchr (begin + 1, ch);\r
++      }\r
++    }\r
++  else\r
++    /* Find the end of the token.  */\r
++    end = strpbrk (begin, delim);\r
++\r
++  if (end)\r
++    {\r
++      /* Terminate the token and set *STRINGP past NUL character.  */\r
++      *end++ = '\0';\r
++      *stringp = end;\r
++    }\r
++  else\r
++    /* No more delimiters; this is the last token.  */\r
++    *stringp = NULL;\r
++\r
++  return begin;\r
++}\r
+diff --git a/configure b/configure\r
+index dae837e..e519abc 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -512,6 +512,17 @@ else\r
+ fi\r
+ rm -f compat/have_strcasestr\r
\r
++printf "Checking for strsep... "\r
++if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep.c > /dev/null 2>&1\r
++then\r
++    printf "Yes.\n"\r
++    have_strsep="1"\r
++else\r
++    printf "No (will use our own instead).\n"\r
++    have_strsep="0"\r
++fi\r
++rm -f compat/have_strsep\r
++\r
+ printf "Checking for standard version of getpwuid_r... "\r
+ if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1\r
+ then\r
+@@ -723,6 +734,10 @@ HAVE_GETLINE = ${have_getline}\r
+ # build its own version)\r
+ HAVE_STRCASESTR = ${have_strcasestr}\r
\r
++# Whether the strsep function is available (if not, then notmuch will\r
++# build its own version)\r
++HAVE_STRSEP = ${have_strsep}\r
++\r
+ # Whether the getpwuid_r function is standards-compliant\r
+ # (if not, then notmuch will compile with -D_POSIX_PTHREAD_SEMANTICS\r
+ # to enable the standards-compliant version -- needed for Solaris)\r
+@@ -782,12 +797,14 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
+                  \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\\r
+                  \$(VALGRIND_CFLAGS)                                   \\\r
+                  -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)                 \\\r
++                 -DHAVE_STRSEP=\$(HAVE_STRSEP)                         \\\r
+                  -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\\r
+                  -DSTD_ASCTIME=\$(STD_ASCTIME)\r
+ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
+                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
+                    \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
+                    -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)               \\\r
++                   -DHAVE_STRSEP=\$(HAVE_STRSEP)                       \\\r
+                    -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\\r
+                    -DSTD_ASCTIME=\$(STD_ASCTIME)\r
+ CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS) \\\r
+-- \r
+1.7.9.2\r
+\r