Skip to content

Commit

Permalink
Rework code
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbASF committed Dec 6, 2023
1 parent c0d1c83 commit 8a4fb5b
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/main/java/org/apache/commons/crypto/jna/OpenSslMacOS.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,13 @@
*/
class OpenSslMacOS {

static native boolean dlopen_preflight(String path);
/*
* The method is declared as 'bool dlopen_preflight(const char* path)', which is not a standard
* JNA type, see:
* http://java-native-access.github.io/jna/5.13.0/javadoc/overview-summary.html#marshalling
* bool appears to be closest to a byte, where non-zero is true and zero is false
*/
static native byte dlopen_preflight(String path);

static native String dlerror();

Expand All @@ -40,10 +46,9 @@ class OpenSslMacOS {
* @return null if OK, else error message
*/
public static String checkLibrary(String path) {
if (dlopen_preflight(path)){
return null;
}
return dlerror();
boolean loadedOK = dlopen_preflight(path) != 0;
String dlerror = dlerror(); // fetch error, and clear for next call
return loadedOK ? null : dlerror;
}

}

0 comments on commit 8a4fb5b

Please sign in to comment.