Re: [PATCH v4 03/16] make shared crypto code behave library-like
[notmuch-archives.git] / a3 / f7f01eaa1851567cc2dd59b587f7f49605ac4b
1 Return-Path: <blakej@foo.net>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id ECF8D431FD4\r
6         for <notmuch@notmuchmail.org>; Sat,  3 Nov 2012 20:24:25 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id HCvaLNsSpd7C for <notmuch@notmuchmail.org>;\r
16         Sat,  3 Nov 2012 20:24:24 -0700 (PDT)\r
17 Received: from foo.net (70-36-235-136.dsl.static.sonic.net [70.36.235.136])\r
18         (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id 268D0431FD0\r
21         for <notmuch@notmuchmail.org>; Sat,  3 Nov 2012 20:24:21 -0700 (PDT)\r
22 Received: from foo.net (localhost [127.0.0.1])\r
23         by foo.net (8.14.5+Sun/8.14.5) with ESMTP id qA43GGPn025686;\r
24         Sat, 3 Nov 2012 20:16:16 -0700 (PDT)\r
25 Received: (from blakej@localhost)\r
26         by foo.net (8.14.5+Sun/8.14.5/Submit) id qA43GG40025685;\r
27         Sat, 3 Nov 2012 20:16:16 -0700 (PDT)\r
28 From: Blake Jones <blakej@foo.net>\r
29 To: notmuch@notmuchmail.org\r
30 Subject: [PATCH 06/10] strsep: check for availability (Solaris support)\r
31 Date: Sat,  3 Nov 2012 20:15:58 -0700\r
32 Message-Id: <1351998962-25135-7-git-send-email-blakej@foo.net>\r
33 X-Mailer: git-send-email 1.7.3.2\r
34 In-Reply-To: <1351998962-25135-1-git-send-email-blakej@foo.net>\r
35 References: <1351998962-25135-1-git-send-email-blakej@foo.net>\r
36 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2\r
37         (foo.net [127.0.0.1]); Sat, 03 Nov 2012 20:16:16 -0700 (PDT)\r
38 X-Mailman-Approved-At: Sun, 04 Nov 2012 01:30:19 -0800\r
39 Cc: Blake Jones <blakej@foo.net>\r
40 X-BeenThere: notmuch@notmuchmail.org\r
41 X-Mailman-Version: 2.1.13\r
42 Precedence: list\r
43 List-Id: "Use and development of the notmuch mail system."\r
44         <notmuch.notmuchmail.org>\r
45 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
47 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
48 List-Post: <mailto:notmuch@notmuchmail.org>\r
49 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
50 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
51         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
52 X-List-Received-Date: Sun, 04 Nov 2012 03:24:26 -0000\r
53 \r
54 Solaris does not ship a version of the strsep() function.  This change\r
55 adds a check to "configure" to see whether notmuch needs to provide its\r
56 own implementation, and if so, it uses the new version in\r
57 "compat/strsep.c" (which was copied from Mutt, and apparently before\r
58 that from glibc).\r
59 ---\r
60  compat/Makefile.local |    4 +++\r
61  compat/compat.h       |    4 +++\r
62  compat/have_strsep.c  |   10 ++++++++\r
63  compat/strsep.c       |   65 +++++++++++++++++++++++++++++++++++++++++++++++++\r
64  configure             |   17 +++++++++++++\r
65  5 files changed, 100 insertions(+)\r
66  create mode 100644 compat/have_strsep.c\r
67  create mode 100644 compat/strsep.c\r
68 \r
69 diff --git a/compat/Makefile.local b/compat/Makefile.local\r
70 index 13f16cd..2c4f65f 100644\r
71 --- a/compat/Makefile.local\r
72 +++ b/compat/Makefile.local\r
73 @@ -13,4 +13,8 @@ ifneq ($(HAVE_STRCASESTR),1)\r
74  notmuch_compat_srcs += $(dir)/strcasestr.c\r
75  endif\r
76  \r
77 +ifneq ($(HAVE_STRSEP),1)\r
78 +notmuch_compat_srcs += $(dir)/strsep.c\r
79 +endif\r
80 +\r
81  SRCS := $(SRCS) $(notmuch_compat_srcs)\r
82 diff --git a/compat/compat.h b/compat/compat.h\r
83 index b750501..1fd2723 100644\r
84 --- a/compat/compat.h\r
85 +++ b/compat/compat.h\r
86 @@ -46,6 +46,10 @@ getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp);\r
87  char* strcasestr(const char *haystack, const char *needle);\r
88  #endif /* !HAVE_STRCASESTR */\r
89  \r
90 +#if !HAVE_STRSEP\r
91 +char *strsep(char **stringp, const char *delim);\r
92 +#endif /* !HAVE_STRSEP */\r
93 +\r
94  /* Silence gcc warnings about unused results.  These warnings exist\r
95   * for a reason; any use of this needs to be justified. */\r
96  #ifdef __GNUC__\r
97 diff --git a/compat/have_strsep.c b/compat/have_strsep.c\r
98 new file mode 100644\r
99 index 0000000..5bd396c\r
100 --- /dev/null\r
101 +++ b/compat/have_strsep.c\r
102 @@ -0,0 +1,10 @@\r
103 +#define _GNU_SOURCE\r
104 +#include <string.h>\r
105 +\r
106 +int main()\r
107 +{\r
108 +    char *found;\r
109 +    char **stringp, const char *delim;\r
110 +\r
111 +    found = strsep(stringp, delim);\r
112 +}\r
113 diff --git a/compat/strsep.c b/compat/strsep.c\r
114 new file mode 100644\r
115 index 0000000..78ab9e7\r
116 --- /dev/null\r
117 +++ b/compat/strsep.c\r
118 @@ -0,0 +1,65 @@\r
119 +/* Copyright (C) 1992, 93, 96, 97, 98, 99, 2004 Free Software Foundation, Inc.\r
120 +   This file is part of the GNU C Library.\r
121 +\r
122 +   The GNU C Library is free software; you can redistribute it and/or\r
123 +   modify it under the terms of the GNU Lesser General Public\r
124 +   License as published by the Free Software Foundation; either\r
125 +   version 2.1 of the License, or (at your option) any later version.\r
126 +\r
127 +   The GNU C Library is distributed in the hope that it will be useful,\r
128 +   but WITHOUT ANY WARRANTY; without even the implied warranty of\r
129 +   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\r
130 +   Lesser General Public License for more details.\r
131 +\r
132 +   You should have received a copy of the GNU Lesser General Public\r
133 +   License along with the GNU C Library; if not, write to the Free\r
134 +   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA\r
135 +   02111-1307 USA.  */\r
136 +\r
137 +#include <string.h>\r
138 +\r
139 +/* Taken from glibc 2.6.1 */\r
140 +\r
141 +char *strsep (char **stringp, const char *delim)\r
142 +{\r
143 +  char *begin, *end;\r
144 +\r
145 +  begin = *stringp;\r
146 +  if (begin == NULL)\r
147 +    return NULL;\r
148 +\r
149 +  /* A frequent case is when the delimiter string contains only one\r
150 +     character.  Here we don't need to call the expensive `strpbrk'\r
151 +     function and instead work using `strchr'.  */\r
152 +  if (delim[0] == '\0' || delim[1] == '\0')\r
153 +    {\r
154 +      char ch = delim[0];\r
155 +\r
156 +      if (ch == '\0')\r
157 +       end = NULL;\r
158 +      else\r
159 +       {\r
160 +         if (*begin == ch)\r
161 +           end = begin;\r
162 +         else if (*begin == '\0')\r
163 +           end = NULL;\r
164 +         else\r
165 +           end = strchr (begin + 1, ch);\r
166 +       }\r
167 +    }\r
168 +  else\r
169 +    /* Find the end of the token.  */\r
170 +    end = strpbrk (begin, delim);\r
171 +\r
172 +  if (end)\r
173 +    {\r
174 +      /* Terminate the token and set *STRINGP past NUL character.  */\r
175 +      *end++ = '\0';\r
176 +      *stringp = end;\r
177 +    }\r
178 +  else\r
179 +    /* No more delimiters; this is the last token.  */\r
180 +    *stringp = NULL;\r
181 +\r
182 +  return begin;\r
183 +}\r
184 diff --git a/configure b/configure\r
185 index dae837e..e519abc 100755\r
186 --- a/configure\r
187 +++ b/configure\r
188 @@ -512,6 +512,17 @@ else\r
189  fi\r
190  rm -f compat/have_strcasestr\r
191  \r
192 +printf "Checking for strsep... "\r
193 +if ${CC} -o compat/have_strsep "$srcdir"/compat/have_strsep.c > /dev/null 2>&1\r
194 +then\r
195 +    printf "Yes.\n"\r
196 +    have_strsep="1"\r
197 +else\r
198 +    printf "No (will use our own instead).\n"\r
199 +    have_strsep="0"\r
200 +fi\r
201 +rm -f compat/have_strsep\r
202 +\r
203  printf "Checking for standard version of getpwuid_r... "\r
204  if ${CC} -o compat/check_getpwuid "$srcdir"/compat/check_getpwuid.c > /dev/null 2>&1\r
205  then\r
206 @@ -723,6 +734,10 @@ HAVE_GETLINE = ${have_getline}\r
207  # build its own version)\r
208  HAVE_STRCASESTR = ${have_strcasestr}\r
209  \r
210 +# Whether the strsep function is available (if not, then notmuch will\r
211 +# build its own version)\r
212 +HAVE_STRSEP = ${have_strsep}\r
213 +\r
214  # Whether the getpwuid_r function is standards-compliant\r
215  # (if not, then notmuch will compile with -D_POSIX_PTHREAD_SEMANTICS\r
216  # to enable the standards-compliant version -- needed for Solaris)\r
217 @@ -782,12 +797,14 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\\r
218                    \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND)   \\\r
219                    \$(VALGRIND_CFLAGS)                                   \\\r
220                    -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)                 \\\r
221 +                  -DHAVE_STRSEP=\$(HAVE_STRSEP)                         \\\r
222                    -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\\r
223                    -DSTD_ASCTIME=\$(STD_ASCTIME)\r
224  CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\\r
225                      \$(TALLOC_CFLAGS) -DHAVE_VALGRIND=\$(HAVE_VALGRIND) \\\r
226                      \$(VALGRIND_CFLAGS) \$(XAPIAN_CXXFLAGS)             \\\r
227                      -DHAVE_STRCASESTR=\$(HAVE_STRCASESTR)               \\\r
228 +                    -DHAVE_STRSEP=\$(HAVE_STRSEP)                       \\\r
229                      -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\\r
230                      -DSTD_ASCTIME=\$(STD_ASCTIME)\r
231  CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(XAPIAN_LDFLAGS) \\\r
232 -- \r
233 1.7.9.2\r
234 \r