| #include <dlfcn.h> |
| |
| #include <stdplus/dl.hpp> |
| |
| #include <format> |
| |
| namespace stdplus |
| { |
| |
| Dl::Dl(const char* file, DlOpenFlags flags) : |
| handle(open(file, static_cast<int>(flags))) |
| {} |
| |
| struct link_map* Dl::linkMap() |
| { |
| struct link_map* ret; |
| info(RTLD_DI_LINKMAP, &ret); |
| return ret; |
| } |
| |
| void Dl::info(int request, void* info) |
| { |
| if (::dlinfo(*handle, request, info) != 0) |
| { |
| throw std::runtime_error("dlinfo"); |
| }; |
| } |
| |
| void* Dl::open(const char* file, int flags) |
| { |
| void* ret = ::dlopen(file, flags); |
| if (ret == nullptr) |
| { |
| throw std::runtime_error(std::format( |
| "dlopen `{}`: {}", file ? file : "<nullptr>", dlerror())); |
| } |
| return ret; |
| } |
| |
| void Dl::close(void*&& handle) |
| { |
| ::dlclose(handle); |
| } |
| |
| } // namespace stdplus |