summaryrefslogtreecommitdiff
path: root/which.c
diff options
context:
space:
mode:
authorToby Goodwin <toby@paccrat.org>2014-09-02 08:01:39 +0100
committerToby Goodwin <toby@paccrat.org>2015-05-16 21:22:10 +0100
commita8699a58d8632f21e897ea5c4900a15483a9a8ca (patch)
treefd8e7910807eb91bcd79d498582959f1d750f9c6 /which.c
parentd884971193ef4934424b77ae862e8b0ecf70bab3 (diff)
release: rc-1.7.2
Diffstat (limited to 'which.c')
-rw-r--r--which.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/which.c b/which.c
index 8abdc60..798d7b0 100644
--- a/which.c
+++ b/which.c
@@ -1,7 +1,7 @@
/* which.c: check to see if a file is executable.
This function was originally written with Maarten Litmaath's which.c as
- a template, but was changed in order to accomodate the possibility of
+ a template, but was changed in order to accommodate the possibility of
rc's running setuid or the possibility of executing files not in the
primary group. Much of this file has been re-vamped by Paul Haahr.
I re-re-vamped the functions that Paul supplied to correct minor bugs
@@ -10,6 +10,7 @@
#include "rc.h"
+#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
@@ -70,6 +71,19 @@ static bool rc_access(char *path, bool verbose) {
return FALSE;
}
+/* replace non-printing characters with question marks in a freshly
+ * allocated string */
+static char *protect(char *in) {
+ int l = strlen(in);
+ char *out = ealloc(l + 1);
+ int i;
+
+ for (i = 0; i < l; ++i)
+ out[i] = isprint(in[i]) ? in[i] : '?';
+ out[i] = '\0';
+ return out;
+}
+
/* return a full pathname by searching $path, and by checking the status of the file */
extern char *which(char *name, bool verbose) {
@@ -119,7 +133,10 @@ extern char *which(char *name, bool verbose) {
if (rc_access(test, FALSE))
return test;
}
- if (verbose)
- fprint(2, "%s not found\n", name);
+ if (verbose) {
+ char *n = protect(name);
+ fprint(2, RC "cannot find `%s'\n", n);
+ efree(n);
+ }
return NULL;
}