Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 46 / 2ddf8ada2e655ceaefa0c03655d25e14e78ff1
1 Return-Path: <dkg@fifthhorseman.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 arlo.cworth.org (Postfix) with ESMTP id 3150A6DE0275\r
6  for <notmuch@notmuchmail.org>; Tue,  9 Feb 2016 13:52:09 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.02\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.02 tagged_above=-999 required=5 tests=[AWL=-0.020]\r
12  autolearn=disabled\r
13 Received: from arlo.cworth.org ([127.0.0.1])\r
14  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
15  with ESMTP id N28myWbFAXH5 for <notmuch@notmuchmail.org>;\r
16  Tue,  9 Feb 2016 13:52:07 -0800 (PST)\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])\r
18  by arlo.cworth.org (Postfix) with ESMTP id 11C5A6DE0231\r
19  for <notmuch@notmuchmail.org>; Tue,  9 Feb 2016 13:52:06 -0800 (PST)\r
20 Received: from fifthhorseman.net (unknown [38.109.115.130])\r
21  by che.mayfirst.org (Postfix) with ESMTPSA id 229E2F991\r
22  for <notmuch@notmuchmail.org>; Tue,  9 Feb 2016 16:52:03 -0500 (EST)\r
23 Received: by fifthhorseman.net (Postfix, from userid 1000)\r
24  id 9DA0B2017F; Tue,  9 Feb 2016 16:52:05 -0500 (EST)\r
25 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>\r
26 To: Notmuch Mail <notmuch@notmuchmail.org>\r
27 Subject: [PATCH v4] add util/search-path.{c,\r
28  h} to test for executables in $PATH\r
29 Date: Tue,  9 Feb 2016 16:52:05 -0500\r
30 Message-Id: <1455054725-952-1-git-send-email-dkg@fifthhorseman.net>\r
31 X-Mailer: git-send-email 2.7.0\r
32 In-Reply-To: <87oabqvy6s.fsf@maritornes.cs.unb.ca>\r
33 References: <87oabqvy6s.fsf@maritornes.cs.unb.ca>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.20\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38  <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
40  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
45  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Tue, 09 Feb 2016 21:52:09 -0000\r
47 \r
48 This is a utility function we can use to see whether an executable is\r
49 available.\r
50 ---\r
51  util/Makefile.local |  2 +-\r
52  util/search-path.c  | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++\r
53  util/search-path.h  | 24 ++++++++++++++++++++++++\r
54  3 files changed, 75 insertions(+), 1 deletion(-)\r
55  create mode 100644 util/search-path.c\r
56  create mode 100644 util/search-path.h\r
57 \r
58 diff --git a/util/Makefile.local b/util/Makefile.local\r
59 index 905f237..8b2b91b 100644\r
60 --- a/util/Makefile.local\r
61 +++ b/util/Makefile.local\r
62 @@ -5,7 +5,7 @@ extra_cflags += -I$(srcdir)/$(dir)\r
63  \r
64  libutil_c_srcs := $(dir)/xutil.c $(dir)/error_util.c $(dir)/hex-escape.c \\r
65                   $(dir)/string-util.c $(dir)/talloc-extra.c $(dir)/zlib-extra.c \\r
66 -               $(dir)/util.c\r
67 +               $(dir)/util.c $(dir)/search-path.c\r
68  \r
69  libutil_modules := $(libutil_c_srcs:.c=.o)\r
70  \r
71 diff --git a/util/search-path.c b/util/search-path.c\r
72 new file mode 100644\r
73 index 0000000..9da21cb\r
74 --- /dev/null\r
75 +++ b/util/search-path.c\r
76 @@ -0,0 +1,50 @@\r
77 +#include "search-path.h"\r
78 +#include <stdlib.h>\r
79 +#include <unistd.h>\r
80 +#include <string.h>\r
81 +#include <sys/types.h>\r
82 +#include <sys/stat.h>\r
83 +#include <fcntl.h>\r
84 +\r
85 +\r
86 +notmuch_bool_t\r
87 +test_for_executable (const char *exename)\r
88 +{\r
89 +    char *path = NULL, *save = NULL, *tok;\r
90 +    notmuch_bool_t ret = FALSE;\r
91 +\r
92 +    if (strchr (exename, '/')) {\r
93 +       if (0 == access (exename, X_OK))\r
94 +           return TRUE;\r
95 +       else\r
96 +           return FALSE;\r
97 +    }\r
98 +\r
99 +    path = getenv ("PATH");\r
100 +    if (path)\r
101 +       path = strdup (path);\r
102 +    else {\r
103 +       size_t n = confstr (_CS_PATH, NULL, 0);\r
104 +       path = (char *) malloc (n);\r
105 +       if (! path)\r
106 +           return FALSE;\r
107 +       confstr (_CS_PATH, path, n);\r
108 +    }\r
109 +\r
110 +    tok = strtok_r (path, ":", &save);\r
111 +    while (tok) {\r
112 +       int dir_fd = open (tok, O_DIRECTORY | O_RDONLY);\r
113 +       if (dir_fd != -1) {\r
114 +           int access = faccessat (dir_fd, exename, X_OK, 0);\r
115 +           close (dir_fd);\r
116 +           if (access == 0) {\r
117 +               ret = TRUE;\r
118 +               break;\r
119 +           }\r
120 +       }\r
121 +       tok = strtok_r (NULL, ":", &save);\r
122 +    }\r
123 +    if (path)\r
124 +       free (path);\r
125 +    return ret;\r
126 +}\r
127 diff --git a/util/search-path.h b/util/search-path.h\r
128 new file mode 100644\r
129 index 0000000..14c4d14\r
130 --- /dev/null\r
131 +++ b/util/search-path.h\r
132 @@ -0,0 +1,24 @@\r
133 +#ifndef _SEARCH_PATH_H\r
134 +#define _SEARCH_PATH_H\r
135 +\r
136 +#include "notmuch.h"\r
137 +\r
138 +/* can an executable be found with the given name?\r
139 + *\r
140 + * Return TRUE only if we can find something to execute with the\r
141 + * associated name.\r
142 + *\r
143 + * if the name has a '/' in it, we look for it directly with\r
144 + * access(exename, X_OK).\r
145 + *\r
146 + * otherwise, we look for it in $PATH (or in confstr(_CS_PATH), if\r
147 + * $PATH is unset).\r
148 + *\r
149 + * This should match the logic for execvp (as well as matching user\r
150 + * expectations, hopefully).\r
151 + */\r
152 +\r
153 +notmuch_bool_t\r
154 +test_for_executable (const char *exename);\r
155 +\r
156 +#endif\r
157 -- \r
158 2.7.0\r
159 \r