]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/LoadableModule.cc
3 /* The original code has this constant ./configure-able.
4 * The "#else" branches use raw dlopen interface and have not been tested.
5 * We can remove that code if we are going to rely on libtool's ltdl in
7 #define XSTD_USE_LIBLTDL 1
10 #include "libltdl/ltdl.h" /* generated file */
15 #include "base/TextException.h"
16 #include "LoadableModule.h"
18 // Note: We must use preprocessor instead of C ifs because if dlopen()
19 // is seen by the static linker, the linker will complain.
21 LoadableModule::LoadableModule(const String
&aName
): theName(aName
), theHandle(0)
24 // Initialise preloaded symbol lookup table.
25 LTDL_SET_PRELOADED_SYMBOLS();
27 throw TexcHere("internal error: cannot initialize libtool module loader");
31 LoadableModule::~LoadableModule()
36 assert(lt_dlexit() == 0); // XXX: replace with a warning
40 bool LoadableModule::loaded() const
42 return theHandle
!= 0;
45 void LoadableModule::load(int mode
)
48 throw TexcHere("internal error: reusing LoadableModule object");
50 theHandle
= openModule(mode
);
53 throw TexcHere(errorMsg());
56 void LoadableModule::unload()
59 throw TexcHere("internal error: unloading not loaded module");
62 throw TexcHere(errorMsg());
67 void *LoadableModule::openModule(int mode
)
70 return lt_dlopen(theName
.termedBuf());
72 return dlopen(theName
.termedBuf(),
73 mode
== lmNow
? RTLD_NOW
: RTLD_LAZY
);
77 bool LoadableModule::closeModule()
80 // we cast to avoid including ltdl.h in LoadableModule.h
81 return lt_dlclose(static_cast<lt_dlhandle
>(theHandle
)) == 0;
83 return dlclose(theHandle
) == 0;
87 const char *LoadableModule::errorMsg()