summaryrefslogtreecommitdiff
path: root/file
diff options
context:
space:
mode:
authorWerner Almesberger <werner@almesberger.net>2016-09-06 20:49:32 (GMT)
committerWerner Almesberger <werner@almesberger.net>2016-09-07 02:58:14 (GMT)
commitaf5cb056e5c2162aef6b868f6b86cf6e711fdc40 (patch)
treed1350596a48e75699baf150b706b474d11e9369a /file
parent6dbc788e8c015a6d63848d00f7a241518dc39210 (diff)
downloadeeshow-af5cb056e5c2162aef6b868f6b86cf6e711fdc40.zip
eeshow-af5cb056e5c2162aef6b868f6b86cf6e711fdc40.tar.gz
eeshow-af5cb056e5c2162aef6b868f6b86cf6e711fdc40.tar.bz2
file/file.c (file_search): apply file_open to a search path
Diffstat (limited to 'file')
-rw-r--r--file/file.c26
-rw-r--r--file/file.h2
2 files changed, 28 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)
{
diff --git a/file/file.h b/file/file.h
index 44d12cc..ff7ea65 100644
--- a/file/file.h
+++ b/file/file.h
@@ -36,6 +36,8 @@ char *file_graft_relative(const char *base, const char *name);
bool file_open_vcs(struct file *file, const char *name);
bool file_open(struct file *file, const char *name,
const struct file *related);
+bool file_search(struct file *file, const char *name,
+ const char **search, unsigned n_search, const struct file *related);
bool file_open_revision(struct file *file, const char *rev, const char *name,
const struct file *related);
bool file_read(struct file *file,