Skip to content

Commit

Permalink
Oops, GetLastError returns a DWORD
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Nov 6, 2023
1 parent 191851b commit c3750c5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,14 @@ static int load_library(JNIEnv *env)

if (!openssl) {
char msg[1000];
#ifdef UNIX
snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, \
GET_LAST_ERROR);
dlerror()); // returns char*
#endif
#ifdef WINDOWS
snprintf(msg, sizeof(msg), "Cannot load %s (%d)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, \
GetLastError()); // returns DWORD
#endif
THROW(env, "java/lang/UnsatisfiedLinkError", msg);
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,14 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_cipher_OpenSslNative_initI

if (!openssl) {
char msg[1000];
#ifdef UNIX
snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, \
GET_LAST_ERROR);
dlerror()); // returns char*
#endif
#ifdef WINDOWS
snprintf(msg, sizeof(msg), "Cannot load %s (%d)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, \
GetLastError()); // returns DWORD
#endif
THROW(env, "java/lang/UnsatisfiedLinkError", msg);
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,7 @@ void *do_dlsym_fallback(JNIEnv *env, void *handle, const char *symbol, const cha
if ((func_ptr = do_dlsym_fallback(env, handle, symbol, fallback)) == NULL) { \
return; \
}
// Macro to hide different method names
#define GET_LAST_ERROR dlerror()

#endif
// Unix part end

Expand Down Expand Up @@ -257,8 +256,7 @@ static FARPROC WINAPI do_dlsym_fallback(JNIEnv *env, HMODULE handle, LPCSTR symb
}
return func_ptr;
}
// Macro to hide different method names
#define GET_LAST_ERROR GetLastError()

#endif
// Windows part end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@ JNIEXPORT void JNICALL Java_org_apache_commons_crypto_random_OpenSslCryptoRandom

if (!openssl) {
char msg[1000];
snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, GET_LAST_ERROR);
#ifdef UNIX
snprintf(msg, sizeof(msg), "Cannot load %s (%s)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, \
dlerror()); // returns char*
#endif
#ifdef WINDOWS
snprintf(msg, sizeof(msg), "Cannot load %s (%d)!", COMMONS_CRYPTO_OPENSSL_LIBRARY, \
GetLastError()); // returns DWORD
#endif
THROW(env, "java/lang/UnsatisfiedLinkError", msg);
return;
}
Expand Down

0 comments on commit c3750c5

Please sign in to comment.