Re: [PATCH v4 01/16] add util/search-path.{c, h} to test for executables in $PATH
[notmuch-archives.git] / bb / ec268bebdc0fc1d0b6160017f3ce3c5cde4ea6
1 Return-Path: <bremner@tethera.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 C276C431FBD\r
6         for <notmuch@notmuchmail.org>; Mon, 27 Jan 2014 06:12:37 -0800 (PST)\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 dRa8c9ENhinp for <notmuch@notmuchmail.org>;\r
16         Mon, 27 Jan 2014 06:12:31 -0800 (PST)\r
17 Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
18         (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits))\r
19         (No client certificate requested)\r
20         by olra.theworths.org (Postfix) with ESMTPS id E1301431FBF\r
21         for <notmuch@notmuchmail.org>; Mon, 27 Jan 2014 06:12:29 -0800 (PST)\r
22 Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
23         (envelope-from <bremner@tethera.net>)\r
24         id 1W7mvL-00060d-Bb; Mon, 27 Jan 2014 10:12:27 -0400\r
25 Received: (nullmailer pid 7908 invoked by uid 1000); Mon, 27 Jan 2014\r
26         14:12:23 -0000\r
27 From: David Bremner <david@tethera.net>\r
28 To: notmuch@notmuchmail.org\r
29 Subject: [PATCH] compat: add canonicalize_file_name\r
30 Date: Mon, 27 Jan 2014 10:12:12 -0400\r
31 Message-Id: <1390831932-7865-1-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 1.8.5.2\r
33 In-Reply-To: <8761p6n0wc.fsf@zancas.localnet>\r
34 References: <8761p6n0wc.fsf@zancas.localnet>\r
35 X-BeenThere: notmuch@notmuchmail.org\r
36 X-Mailman-Version: 2.1.13\r
37 Precedence: list\r
38 List-Id: "Use and development of the notmuch mail system."\r
39         <notmuch.notmuchmail.org>\r
40 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
41         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
42 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
43 List-Post: <mailto:notmuch@notmuchmail.org>\r
44 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
45 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
46         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
47 X-List-Received-Date: Mon, 27 Jan 2014 14:12:37 -0000\r
48 \r
49 the POSIX 2008 behaviour of realpath is not available everywhere so we\r
50 provide a simple wrapper function.  We use (and provide) the gnu\r
51 extension canonicalize_file_name to make it cleaner to test for the\r
52 feature we need; otherwise we have to rely on realpath segfaulting if\r
53 the second argument is null.\r
54 ---\r
55  compat/Makefile.local                |  4 ++++\r
56  compat/canonicalize_file_name.c      | 18 ++++++++++++++++++\r
57  compat/compat.h                      |  8 ++++++++\r
58  compat/have_canonicalize_file_name.c | 10 ++++++++++\r
59  configure                            | 16 ++++++++++++++++\r
60  notmuch-config.c                     |  2 +-\r
61  6 files changed, 57 insertions(+), 1 deletion(-)\r
62  create mode 100644 compat/canonicalize_file_name.c\r
63  create mode 100644 compat/have_canonicalize_file_name.c\r
64 \r
65 diff --git a/compat/Makefile.local b/compat/Makefile.local\r
66 index b0d5417..bcb9f0e 100644\r
67 --- a/compat/Makefile.local\r
68 +++ b/compat/Makefile.local\r
69 @@ -5,6 +5,10 @@ extra_cflags += -I$(srcdir)/$(dir)\r
70  \r
71  notmuch_compat_srcs :=\r
72  \r
73 +ifneq ($(HAVE_CANONICALIZE_FILE_NAME),1)\r
74 +notmuch_compat_srcs += $(dir)/canonicalize_file_name.c\r
75 +endif\r
76 +\r
77  ifneq ($(HAVE_GETLINE),1)\r
78  notmuch_compat_srcs += $(dir)/getline.c $(dir)/getdelim.c\r
79  endif\r
80 diff --git a/compat/canonicalize_file_name.c b/compat/canonicalize_file_name.c\r
81 new file mode 100644\r
82 index 0000000..e92c0f6\r
83 --- /dev/null\r
84 +++ b/compat/canonicalize_file_name.c\r
85 @@ -0,0 +1,18 @@\r
86 +#include "compat.h"\r
87 +#include <limits.h>\r
88 +#undef _GNU_SOURCE\r
89 +#include <stdlib.h>\r
90 +\r
91 +char *\r
92 +canonicalize_file_name (const char * path)\r
93 +{\r
94 +#ifdef PATH_MAX\r
95 +    char *resolved_path =  malloc (PATH_MAX+1);\r
96 +    if (resolved_path == NULL)\r
97 +       return NULL;\r
98 +\r
99 +    return realpath (path, resolved_path);\r
100 +#else\r
101 +#error undefined PATH_MAX _and_ missing canonicalize_file_name not supported\r
102 +#endif\r
103 +}\r
104 diff --git a/compat/compat.h b/compat/compat.h\r
105 index 5a402d5..634d505 100644\r
106 --- a/compat/compat.h\r
107 +++ b/compat/compat.h\r
108 @@ -37,6 +37,14 @@ extern "C" {\r
109  #define _POSIX_PTHREAD_SEMANTICS 1\r
110  #endif\r
111  \r
112 +#if !HAVE_CANONICALIZE_FILE_NAME\r
113 +/* we only call this function from C, and this makes testing easier */\r
114 +#ifndef __cplusplus\r
115 +char *\r
116 +canonicalize_file_name (const char *path);\r
117 +#endif\r
118 +#endif\r
119 +\r
120  #if !HAVE_GETLINE\r
121  #include <stdio.h>\r
122  #include <unistd.h>\r
123 diff --git a/compat/have_canonicalize_file_name.c b/compat/have_canonicalize_file_name.c\r
124 new file mode 100644\r
125 index 0000000..24c848e\r
126 --- /dev/null\r
127 +++ b/compat/have_canonicalize_file_name.c\r
128 @@ -0,0 +1,10 @@\r
129 +#define _GNU_SOURCE\r
130 +#include <stdlib.h>\r
131 +\r
132 +int main()\r
133 +{\r
134 +    char *found;\r
135 +    char *string;\r
136 +\r
137 +    found = canonicalize_file_name (string);\r
138 +}\r
139 diff --git a/configure b/configure\r
140 index 13b6062..5b7c941 100755\r
141 --- a/configure\r
142 +++ b/configure\r
143 @@ -526,6 +526,18 @@ EOF\r
144      exit 1\r
145  fi\r
146  \r
147 +printf "Checking for canonicalize_file_name... "\r
148 +if ${CC} -o compat/have_canonicalize_file_name "$srcdir"/compat/have_canonicalize_file_name.c > /dev/null 2>&1\r
149 +then\r
150 +    printf "Yes.\n"\r
151 +    have_canonicalize_file_name=1\r
152 +else\r
153 +    printf "No (will use our own instead).\n"\r
154 +    have_canonicalize_file_name=0\r
155 +fi\r
156 +rm -f compat/have_canonicalize_file_name\r
157 +\r
158 +\r
159  printf "Checking for getline... "\r
160  if ${CC} -o compat/have_getline "$srcdir"/compat/have_getline.c > /dev/null 2>&1\r
161  then\r
162 @@ -751,6 +763,10 @@ zsh_completion_dir = ${ZSHCOMLETIONDIR:=\$(prefix)/share/zsh/functions/Completio\r
163  \r
164  # Whether the getline function is available (if not, then notmuch will\r
165  # build its own version)\r
166 +HAVE_CANONICALIZE_FILE_NAME = ${have_canonicalize_file_name}\r
167 +\r
168 +# Whether the getline function is available (if not, then notmuch will\r
169 +# build its own version)\r
170  HAVE_GETLINE = ${have_getline}\r
171  \r
172  # Whether the strcasestr function is available (if not, then notmuch will\r
173 diff --git a/notmuch-config.c b/notmuch-config.c\r
174 index 8d28653..4886d36 100644\r
175 --- a/notmuch-config.c\r
176 +++ b/notmuch-config.c\r
177 @@ -454,7 +454,7 @@ notmuch_config_save (notmuch_config_t *config)\r
178      }\r
179  \r
180      /* Try not to overwrite symlinks. */\r
181 -    filename = realpath (config->filename, NULL);\r
182 +    filename = canonicalize_file_name (config->filename);\r
183      if (! filename) {\r
184         if (errno == ENOENT) {\r
185             filename = strdup (config->filename);\r
186 -- \r
187 1.8.5.2\r
188 \r