• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.3
/src/lib/utils/dyn_load/dyn_load.cpp
1
/*
2
* Dynamically Loaded Object
3
* (C) 2010 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/dyn_load.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/fmt.h>
12
#include <sstream>
13

14
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
15
   #include <dlfcn.h>
16
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
17
   #define NOMINMAX 1
18
   #define _WINSOCKAPI_  // stop windows.h including winsock.h
19
   #include <windows.h>
20
#endif
21

22
namespace Botan {
23

24
namespace {
25

26
void raise_runtime_loader_exception(std::string_view lib_name, const char* msg) {
1✔
27
   std::ostringstream err;
1✔
28
   err << "Failed to load " << lib_name << ": ";
1✔
29
   if(msg)
1✔
30
      err << msg;
1✔
31
   else
32
      err << "Unknown error";
×
33

34
   throw System_Error(err.str(), 0);
2✔
35
}
1✔
36

37
}
38

39
Dynamically_Loaded_Library::Dynamically_Loaded_Library(std::string_view library) : m_lib_name(library), m_lib(nullptr) {
76✔
40
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
41
   m_lib = ::dlopen(m_lib_name.c_str(), RTLD_LAZY);
76✔
42

43
   if(!m_lib)
76✔
44
      raise_runtime_loader_exception(m_lib_name, ::dlerror());
1✔
45

46
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
47
   m_lib = ::LoadLibraryA(m_lib_name.c_str());
48

49
   if(!m_lib)
50
      raise_runtime_loader_exception(m_lib_name, "LoadLibrary failed");
51
#endif
52

53
   if(!m_lib)
75✔
54
      raise_runtime_loader_exception(m_lib_name, "Dynamic load not supported");
55
}
76✔
56

57
Dynamically_Loaded_Library::~Dynamically_Loaded_Library() {
75✔
58
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
59
   ::dlclose(m_lib);
75✔
60
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
61
   ::FreeLibrary(reinterpret_cast<HMODULE>(m_lib));
62
#endif
63
}
75✔
64

65
void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) {
77✔
66
   void* addr = nullptr;
77✔
67

68
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
69
   addr = ::dlsym(m_lib, symbol.c_str());
77✔
70
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
71
   addr = reinterpret_cast<void*>(::GetProcAddress(reinterpret_cast<HMODULE>(m_lib), symbol.c_str()));
72
#endif
73

74
   if(!addr) {
77✔
75
      throw Invalid_Argument(fmt("Failed to resolve symbol {} in {}", symbol, m_lib_name));
×
76
   }
77

78
   return addr;
77✔
79
}
80

81
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc