diff options
author | Richard Levitte <levitte@openssl.org> | 2020-11-25 07:56:08 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-12-01 11:06:03 +0100 |
commit | 9800b1a0da90159a6bd6f5dbf8df6249ee967946 (patch) | |
tree | 45ed19f018debff56ce391b951584a0ad616a001 /test/simpledynamic.c | |
parent | endecode_test.c: Add warning that 512-bit DH key size is for testing only (diff) | |
download | openssl-9800b1a0da90159a6bd6f5dbf8df6249ee967946.tar.xz openssl-9800b1a0da90159a6bd6f5dbf8df6249ee967946.zip |
TEST: Break out the local dynamic loading code from shlibloadtest.c
The result is "simpledynamic.c", or "sd" for short.
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13507)
Diffstat (limited to 'test/simpledynamic.c')
-rw-r--r-- | test/simpledynamic.c | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/test/simpledynamic.c b/test/simpledynamic.c new file mode 100644 index 0000000000..41a910caa2 --- /dev/null +++ b/test/simpledynamic.c @@ -0,0 +1,76 @@ +/* + * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stdlib.h> /* For NULL */ +#include <openssl/macros.h> /* For NON_EMPTY_TRANSLATION_UNIT */ +#include "simpledynamic.h" + +#if defined(DSO_DLFCN) + +int sd_load(const char *filename, SD *lib, int type) +{ + int dl_flags = type; +#ifdef _AIX + if (filename[strlen(filename) - 1] == ')') + dl_flags |= RTLD_MEMBER; +#endif + *lib = dlopen(filename, dl_flags); + return *lib == NULL ? 0 : 1; +} + +int sd_sym(SD lib, const char *symname, SD_SYM *sym) +{ + *sym = dlsym(lib, symname); + return *sym != NULL; +} + +int sd_close(SD lib) +{ + return dlclose(lib) != 0 ? 0 : 1; +} + +const char *sd_error(void) +{ + return dlerror(); +} + +#elif defined(DSO_WIN32) + +nt sd_load(const char *filename, SD *lib, ossl_unused int type) +{ + *lib = LoadLibraryA(filename); + return *lib == NULL ? 0 : 1; +} + +int sd_sym(SD lib, const char *symname, SD_SYM *sym) +{ + *sym = (SD_SYM)GetProcAddress(lib, symname); + return *sym != NULL; +} + +int sd_close(SD lib) +{ + return FreeLibrary(lib) == 0 ? 0 : 1; +} + +const char *sd_error(void) +{ + static char buffer[255]; + + buffer[0] = '\0'; + FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(), 0, + buffer, sizeof(buffer), NULL); + return buffer; +} + +#else + +NON_EMPTY_TRANSLATION_UNIT + +#endif |