0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 01:59:33 +02:00

ircd::mods::ldso: Add getter by name.

This commit is contained in:
Jason Volk 2019-06-02 17:05:36 -07:00
parent 068bb44937
commit b4e44a0ce1
2 changed files with 42 additions and 0 deletions

View file

@ -24,6 +24,9 @@ extern "C"
/// Platform-dependent interface on ELF+ld.so supporting compilations.
namespace ircd::mods::ldso
{
IRCD_EXCEPTION(mods::error, error)
IRCD_EXCEPTION(error, not_found);
using link_closure = std::function<bool (struct link_map &)>;
using semantic_version = std::array<long, 3>;
@ -40,4 +43,7 @@ namespace ircd::mods::ldso
bool has_soname(const string_view &name);
bool has(const string_view &name);
size_t count();
struct link_map *get(std::nothrow_t, const string_view &name);
struct link_map &get(const string_view &name);
}

View file

@ -20,6 +20,42 @@
// mods/ldso.h
//
struct link_map &
ircd::mods::ldso::get(const string_view &name)
{
struct link_map *const ret
{
get(std::nothrow, name)
};
if(unlikely(!ret))
throw not_found
{
"No library '%s' is currently mapped.", name
};
return *ret;
}
struct link_map *
ircd::mods::ldso::get(std::nothrow_t,
const string_view &name)
{
struct link_map *ret{nullptr};
for_each([&name, &ret]
(struct link_map &link)
{
if(ldso::name(link) == name)
{
ret = &link;
return false;
}
else return true;
});
return ret;
}
size_t
ircd::mods::ldso::count()
{