quickhash
quickhash copied to clipboard
libewf: on Linux check for system library first?
Wouldn't it make sense on Linux to look for libewf.so.2
in the system directories first and then try to load the bundled library?
I also think the extra FileExists()
checks aren't needed.
{$ifdef Linux}
// look for system library first
fLibHandle := LoadLibrary('libewf.so.2');
{$ifdef CPU64}
// on 64 bit systems look for our own library next
if fLibHandle = nilhandle then
begin
libFileName := ExtractFilePath(Application.ExeName)+IncludeTrailingPathDelimiter(LIB_FOLDER)+'libewf-Linux-x64.so';
fLibHandle := LoadLibrary(libFileName);
end
{$endif}
if fLibHandle <> nilhandle then
begin
// success
end
{$endif}
I can see the logic, but, the "problem" with that library (from my perspective) is it is updated (well maintained) regularly. If QH uses the system SO.2 file that was not shipped with QH, there's a good chance some of the function calls will, at some stage, maybe sooner rather than later, start to fail. At least by making it call the shipped SO file that I compiled for distribution with QH itself, I know that all my calls from QH will work with that library, until the time comes that I recompile the libewf library myself.
If QH uses the system SO.2 file that was not shipped with QH, there's a good chance some of the function calls will, at some stage, maybe sooner rather than later, start to fail.
As long as the library doesn't receive any updates that break the current API the soname libewf.so.2
will stay the same, otherwise the number will be bumped to libewf.so.3
etc, in which case loading will fail anyway.
Additionally you could put the GetProcAddress part into a separate function so if loading the system library succeeds but loading the symbols fails you can fall back to the bundled library (pseudo code):
HANDLE handle;
function load_ewf_library(string filename) -> bool
{
handle = LoadLibrary("libewf.so.2");
if (!handle) return false;
if (load_symbol_addresses(handle) == false) {
FreeLibrary(handle);
return false;
}
return true;
}
// ...
if (load_ewf_library("libewf.so.2") == false &&
load_ewf_library(bundled_library_path) == false)
{
// error: cannot load library
}
Here you can find a modified version: https://github.com/darealshinji/quickhash/tree/libewf
Here's the diff with the changes: https://github.com/darealshinji/quickhash/commit/913fb85bd88d22dcbc8324ac68b886559917ecf8
It builds but I haven't checked if it actually does what it's supposed to do.