13 #ifndef __STOUT_POSIX_DYNAMICLIBRARY_HPP__
14 #define __STOUT_POSIX_DYNAMICLIBRARY_HPP__
41 if (handle_ !=
nullptr) {
49 if (handle_ !=
nullptr) {
50 return Error(
"Library already opened");
53 handle_ = dlopen(path.c_str(), RTLD_NOW);
55 if (handle_ ==
nullptr) {
56 return Error(
"Could not load library '" + path +
"': " + dlerror());
66 if (handle_ ==
nullptr) {
67 return Error(
"Could not close library; handle was already `nullptr`");
70 if (dlclose(handle_) != 0) {
72 "Could not close library '" +
73 (path_.
isSome() ? path_.
get() :
"") +
"': " + dlerror());
84 if (handle_ ==
nullptr) {
86 "Could not get symbol '" + name +
"'; library handle was `nullptr`");
89 void* symbol = dlsym(handle_, name.c_str());
91 if (symbol ==
nullptr) {
93 "Error looking up symbol '" + name +
"' in '" +
94 (path_.
isSome() ? path_.
get() :
"") +
"' : " + dlerror());
105 #endif // __STOUT_POSIX_DYNAMICLIBRARY_HPP__
Try< Nothing > open(const std::string &path)
Definition: dynamiclibrary.hpp:46
Definition: nothing.hpp:16
Definition: errorbase.hpp:35
Try< void * > loadSymbol(const std::string &name)
Definition: dynamiclibrary.hpp:82
bool isSome() const
Definition: option.hpp:115
const T & get() const &
Definition: option.hpp:118
DynamicLibrary is a very simple wrapper around the programming interface to the dynamic linking loade...
Definition: dynamiclibrary.hpp:28
DynamicLibrary()
Definition: dynamiclibrary.hpp:31
Try< Nothing > close()
Definition: dynamiclibrary.hpp:64
virtual ~DynamicLibrary()
Definition: dynamiclibrary.hpp:39
constexpr const char * name
Definition: shell.hpp:41