2 * Copyright 2016-2021 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
11 #include <stdlib.h> /* For NULL */
12 #include <openssl/macros.h> /* For NON_EMPTY_TRANSLATION_UNIT */
13 #include <openssl/e_os2.h>
14 #include "simpledynamic.h"
16 #if defined(DSO_DLFCN) || defined(DSO_VMS)
18 int sd_load(const char *filename, SD *lib, int type)
22 if (filename[strlen(filename) - 1] == ')')
23 dl_flags |= RTLD_MEMBER;
25 *lib = dlopen(filename, dl_flags);
26 return *lib == NULL ? 0 : 1;
29 int sd_sym(SD lib, const char *symname, SD_SYM *sym)
31 *sym = dlsym(lib, symname);
37 return dlclose(lib) != 0 ? 0 : 1;
40 const char *sd_error(void)
45 #elif defined(DSO_WIN32)
47 int sd_load(const char *filename, SD *lib, ossl_unused int type)
49 *lib = LoadLibraryA(filename);
50 return *lib == NULL ? 0 : 1;
53 int sd_sym(SD lib, const char *symname, SD_SYM *sym)
55 *sym = (SD_SYM)GetProcAddress(lib, symname);
61 return FreeLibrary(lib) == 0 ? 0 : 1;
64 const char *sd_error(void)
66 static char buffer[255];
69 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0,
70 buffer, sizeof(buffer), NULL);
76 NON_EMPTY_TRANSLATION_UNIT