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 "simpledynamic.h"
14 #if defined(DSO_DLFCN)
16 int sd_load(const char *filename
, SD
*lib
, int type
)
20 if (filename
[strlen(filename
) - 1] == ')')
21 dl_flags
|= RTLD_MEMBER
;
23 *lib
= dlopen(filename
, dl_flags
);
24 return *lib
== NULL
? 0 : 1;
27 int sd_sym(SD lib
, const char *symname
, SD_SYM
*sym
)
29 *sym
= dlsym(lib
, symname
);
35 return dlclose(lib
) != 0 ? 0 : 1;
38 const char *sd_error(void)
43 #elif defined(DSO_WIN32)
45 nt
sd_load(const char *filename
, SD
*lib
, ossl_unused
int type
)
47 *lib
= LoadLibraryA(filename
);
48 return *lib
== NULL
? 0 : 1;
51 int sd_sym(SD lib
, const char *symname
, SD_SYM
*sym
)
53 *sym
= (SD_SYM
)GetProcAddress(lib
, symname
);
59 return FreeLibrary(lib
) == 0 ? 0 : 1;
62 const char *sd_error(void)
64 static char buffer
[255];
67 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(), 0,
68 buffer
, sizeof(buffer
), NULL
);
74 NON_EMPTY_TRANSLATION_UNIT