summaryrefslogtreecommitdiff
path: root/file/file.c
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-06 17:49:32 -0300
committerWerner Almesberger <werner@almesberger.net>2016-09-06 23:58:14 -0300
commitaf5cb056e5c2162aef6b868f6b86cf6e711fdc40 (patch)
treed1350596a48e75699baf150b706b474d11e9369a /file/file.c
parent6dbc788e8c015a6d63848d00f7a241518dc39210 (diff)
downloadeeshow-af5cb056e5c2162aef6b868f6b86cf6e711fdc40.tar.gz
eeshow-af5cb056e5c2162aef6b868f6b86cf6e711fdc40.tar.bz2
eeshow-af5cb056e5c2162aef6b868f6b86cf6e711fdc40.zip
file/file.c (file_search): apply file_open to a search path
Diffstat (limited to 'file/file.c')
-rw-r--r--file/file.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/file/file.c b/file/file.c
index 7b7ebca..2230816 100644
--- a/file/file.c
+++ b/file/file.c
@@ -213,6 +213,32 @@ fail:
}
+bool file_search(struct file *file, const char *name,
+ const char **search, unsigned n_search, const struct file *related)
+{
+ unsigned i;
+ char *s;
+
+ /*
+ * Caller should try file_open(file, name, ...) first, and only then
+ * try file_search. Thus, if there's a /, we already know that the file
+ * can't be found.
+ */
+ if (*name == '/')
+ return 0;
+
+ for (i = 0; i != n_search; i++) {
+ alloc_printf(&s, "%s/%s", search[i], name);
+ if (file_open(file, s, related)) {
+ free(s);
+ return 1;
+ }
+ free(s);
+ }
+ return 0;
+}
+
+
bool file_open_revision(struct file *file, const char *rev, const char *name,
const struct file *related)
{