1 | //===----------------------------------------------------------------------===// |
2 | // DuckDB |
3 | // |
4 | // duckdb/common/dl.hpp |
5 | // |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
9 | #pragma once |
10 | |
11 | #include "duckdb/common/windows.hpp" |
12 | #include "duckdb/common/local_file_system.hpp" |
13 | |
14 | #ifndef _WIN32 |
15 | #include <dlfcn.h> |
16 | #else |
17 | #define RTLD_NOW 0 |
18 | #define RTLD_LOCAL 0 |
19 | #endif |
20 | |
21 | namespace duckdb { |
22 | |
23 | #ifdef _WIN32 |
24 | |
25 | inline void *dlopen(const char *file, int mode) { |
26 | D_ASSERT(file); |
27 | return (void *)LoadLibrary(file); |
28 | } |
29 | |
30 | inline void *dlsym(void *handle, const char *name) { |
31 | D_ASSERT(handle); |
32 | return (void *)GetProcAddress((HINSTANCE)handle, name); |
33 | } |
34 | |
35 | inline std::string GetDLError(void) { |
36 | return LocalFileSystem::GetLastErrorAsString(); |
37 | } |
38 | |
39 | #else |
40 | |
41 | inline std::string GetDLError(void) { |
42 | return dlerror(); |
43 | } |
44 | |
45 | #endif |
46 | |
47 | } // namespace duckdb |
48 | |