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

randombit / botan / 19596147897

22 Nov 2025 01:25PM UTC coverage: 90.629% (+0.002%) from 90.627%
19596147897

Pull #5168

github

web-flow
Merge 9ea34d5a5 into f8eb34002
Pull Request #5168: Add clang-format 17 formatting rules for attributes and inline assembly

100659 of 111067 relevant lines covered (90.63%)

12696690.87 hits per line

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

91.67
/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 <botan/internal/target_info.h>
13
#include <sstream>
14

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

23
namespace Botan {
24

25
namespace {
26

27
[[noreturn]]
28
void raise_runtime_loader_exception(std::string_view lib_name, const char* msg) {
1✔
29
   std::ostringstream err;
1✔
30
   err << "Failed to load " << lib_name << ": ";
1✔
31
   if(msg != nullptr) {
1✔
32
      err << msg;
1✔
33
   } else {
34
      err << "Unknown error";
×
35
   }
36

37
   throw System_Error(err.str(), 0);
2✔
38
}
1✔
39

40
void* open_shared_library(const std::string& library) {
76✔
41
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
42
   void* lib = ::dlopen(library.c_str(), RTLD_LAZY);
76✔
43

44
   if(lib != nullptr) {
76✔
45
      return lib;
75✔
46
   } else {
47
      raise_runtime_loader_exception(library, ::dlerror());
1✔
48
   }
49

50
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
51
   void* lib = ::LoadLibraryA(library.c_str());
52

53
   if(lib != nullptr) {
54
      return lib;
55
   } else {
56
      raise_runtime_loader_exception(library, "LoadLibrary failed");
57
   }
58
#else
59
   raise_runtime_loader_exception(library, "Dynamic loading not supported");
60
#endif
61
}
62

63
}  // namespace
64

65
Dynamically_Loaded_Library::Dynamically_Loaded_Library(std::string_view library) :
76✔
66
      m_lib_name(library), m_lib(open_shared_library(m_lib_name)) {}
76✔
67

68
Dynamically_Loaded_Library::~Dynamically_Loaded_Library() {
75✔
69
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
70
   ::dlclose(m_lib);
75✔
71
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
72
   ::FreeLibrary(reinterpret_cast<HMODULE>(m_lib));
73
#endif
74
}
75✔
75

76
void* Dynamically_Loaded_Library::resolve_symbol(const std::string& symbol) {
77✔
77
   void* addr = nullptr;
77✔
78

79
#if defined(BOTAN_TARGET_OS_HAS_POSIX1)
80
   addr = ::dlsym(m_lib, symbol.c_str());
77✔
81
#elif defined(BOTAN_TARGET_OS_HAS_WIN32)
82
   addr = reinterpret_cast<void*>(::GetProcAddress(reinterpret_cast<HMODULE>(m_lib), symbol.c_str()));
83
#endif
84

85
   if(addr == nullptr) {
77✔
86
      throw Invalid_Argument(fmt("Failed to resolve symbol {} in {}", symbol, m_lib_name));
×
87
   }
88

89
   return addr;
77✔
90
}
91

92
}  // namespace Botan
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

© 2026 Coveralls, Inc