extension.cpp 648 B

123456789101112131415161718192021222324252627282930313233
  1. #include <dlfcn.h>
  2. #include "extension.h"
  3. bool extension_t::Load( const char* filename )
  4. {
  5. // load libary
  6. lib_handle = dlopen( filename, RTLD_LAZY );
  7. if( lib_handle == NULL )
  8. {
  9. ERROR( "File \"" << filename << "\": " << dlerror() );
  10. return false;
  11. }
  12. // get FooBar
  13. foobar_ptr = (int(*)(void*))( dlsym(lib_handle, "FooBar") );
  14. if( foobar_ptr == NULL )
  15. {
  16. ERROR( "File \"" << filename << "\": \"FooBar\" entry symbol not found: " << dlerror() );
  17. return false;
  18. }
  19. return true;
  20. }
  21. void extension_t::Unload()
  22. {
  23. DEBUG_ERR( lib_handle==NULL || foobar_ptr==NULL );
  24. dlclose( lib_handle );
  25. lib_handle = NULL;
  26. foobar_ptr = NULL;
  27. }