2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
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
10 #include <stdlib.h> /* For NULL */
11 #include <openssl/macros.h> /* For NON_EMPTY_TRANSLATION_UNIT */
12 #include <openssl/e_os2.h>
13 #include "simpledynamic.h"
15 #if defined(DSO_DLFCN)
17 int sd_load(const char *filename, SD *lib, int type)
21 if (filename[strlen(filename) - 1] == ')')
22 dl_flags |= RTLD_MEMBER;
24 *lib = dlopen(filename, dl_flags);
25 return *lib == NULL ? 0 : 1;
28 int sd_sym(SD lib, const char *symname, SD_SYM *sym)
30 *sym = dlsym(lib, symname);
36 return dlclose(lib) != 0 ? 0 : 1;
39 const char *sd_error(void)
44 #elif defined(DSO_WIN32)
46 int sd_load(const char *filename, SD *lib, ossl_unused int type)
48 *lib = LoadLibraryA(filename);
49 return *lib == NULL ? 0 : 1;
52 int sd_sym(SD lib, const char *symname, SD_SYM *sym)
54 *sym = (SD_SYM)GetProcAddress(lib, symname);
60 return FreeLibrary(lib) == 0 ? 0 : 1;
63 const char *sd_error(void)
65 static char buffer[255];
68 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
69 buffer, sizeof(buffer), NULL);
75 NON_EMPTY_TRANSLATION_UNIT