diff --git a/ircd/modules.cc b/ircd/modules.cc index 4db90305f..9ada5740e 100644 --- a/ircd/modules.cc +++ b/ircd/modules.cc @@ -81,6 +81,7 @@ filesystem::path prefix_if_relative(const filesystem::path &path); filesystem::path postfixed(const filesystem::path &path); std::string postfixed(const std::string &name); +template R info(const filesystem::path &, F&& closure); std::vector sections(const filesystem::path &path); std::vector symbols(const filesystem::path &path); std::vector symbols(const filesystem::path &path, const std::string §ion); @@ -537,23 +538,50 @@ ircd::mods::symbols(const std::string &fullpath, std::vector ircd::mods::sections(const filesystem::path &path) { - boost::dll::library_info info(path); - return info.sections(); + return info>(path, [] + (boost::dll::library_info &info) + { + return info.sections(); + }); } std::vector ircd::mods::symbols(const filesystem::path &path) { - boost::dll::library_info info(path); - return info.symbols(); + return info>(path, [] + (boost::dll::library_info &info) + { + return info.symbols(); + }); } std::vector ircd::mods::symbols(const filesystem::path &path, const std::string §ion) { + return info>(path, [§ion] + (boost::dll::library_info &info) + { + return info.symbols(section); + }); +} + +template +R +ircd::mods::info(const filesystem::path &path, + F&& closure) +{ + if(!exists(path)) + throw filesystem_error("`%s' does not exist", + path.string().c_str()); + + if(!is_regular_file(path)) + throw filesystem_error("`%s' is not a file", + path.string().c_str()); + boost::dll::library_info info(path); - return info.symbols(section); + return closure(info); } void