+namespace {
+
+string search_for_file(const string &filename)
+{
+ // Look for the file in all theme_dirs until we find one;
+ // that will be the permanent resolution of this file, whether
+ // it is actually valid or not.
+ // We store errors from all the attempts, and show them
+ // once we know we can't find any of them.
+ vector<string> errors;
+ for (const string &dir : global_flags.theme_dirs) {
+ string pathname = dir + "/" + filename;
+ if (access(pathname.c_str(), O_RDONLY) == 0) {
+ return pathname;
+ } else {
+ char buf[512];
+ snprintf(buf, sizeof(buf), "%s: %s", pathname.c_str(), strerror(errno));
+ errors.push_back(buf);
+ }
+ }
+
+ for (const string &error : errors) {
+ fprintf(stderr, "%s\n", error.c_str());
+ }
+ fprintf(stderr, "Couldn't find %s in any directory in --theme-dirs, exiting.\n",
+ filename.c_str());
+ exit(1);
+}
+
+} // namespace
+