]>
Commit | Line | Data |
---|---|---|
9800b1a0 RL |
1 | /* |
2 | * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. | |
3 | * | |
4 | * Licensed under the Apache License 2.0 (the "License"). You may not use | |
5 | * this file except in compliance with the License. You can obtain a copy | |
6 | * in the file LICENSE in the source distribution or at | |
7 | * https://www.openssl.org/source/license.html | |
8 | */ | |
9 | ||
10 | #include <stdlib.h> /* For NULL */ | |
11 | #include <openssl/macros.h> /* For NON_EMPTY_TRANSLATION_UNIT */ | |
9feb2fce | 12 | #include <openssl/e_os2.h> |
9800b1a0 RL |
13 | #include "simpledynamic.h" |
14 | ||
15 | #if defined(DSO_DLFCN) | |
16 | ||
17 | int sd_load(const char *filename, SD *lib, int type) | |
18 | { | |
19 | int dl_flags = type; | |
20 | #ifdef _AIX | |
21 | if (filename[strlen(filename) - 1] == ')') | |
22 | dl_flags |= RTLD_MEMBER; | |
23 | #endif | |
24 | *lib = dlopen(filename, dl_flags); | |
25 | return *lib == NULL ? 0 : 1; | |
26 | } | |
27 | ||
28 | int sd_sym(SD lib, const char *symname, SD_SYM *sym) | |
29 | { | |
30 | *sym = dlsym(lib, symname); | |
31 | return *sym != NULL; | |
32 | } | |
33 | ||
34 | int sd_close(SD lib) | |
35 | { | |
36 | return dlclose(lib) != 0 ? 0 : 1; | |
37 | } | |
38 | ||
39 | const char *sd_error(void) | |
40 | { | |
41 | return dlerror(); | |
42 | } | |
43 | ||
44 | #elif defined(DSO_WIN32) | |
45 | ||
9feb2fce | 46 | int sd_load(const char *filename, SD *lib, ossl_unused int type) |
9800b1a0 RL |
47 | { |
48 | *lib = LoadLibraryA(filename); | |
49 | return *lib == NULL ? 0 : 1; | |
50 | } | |
51 | ||
52 | int sd_sym(SD lib, const char *symname, SD_SYM *sym) | |
53 | { | |
54 | *sym = (SD_SYM)GetProcAddress(lib, symname); | |
55 | return *sym != NULL; | |
56 | } | |
57 | ||
58 | int sd_close(SD lib) | |
59 | { | |
60 | return FreeLibrary(lib) == 0 ? 0 : 1; | |
61 | } | |
62 | ||
63 | const char *sd_error(void) | |
64 | { | |
65 | static char buffer[255]; | |
66 | ||
67 | buffer[0] = '\0'; | |
68 | FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, | |
69 | buffer, sizeof(buffer), NULL); | |
70 | return buffer; | |
71 | } | |
72 | ||
73 | #else | |
74 | ||
75 | NON_EMPTY_TRANSLATION_UNIT | |
76 | ||
77 | #endif |