From d52964b6fc304af55e733ff5ea8c2cb65b2959e4 Mon Sep 17 00:00:00 2001 From: James Jones Date: Tue, 12 Jan 2021 15:59:42 -0800 Subject: [PATCH] Support alternate file path lists for loading libs Add a new constructor to the dynamic library loader helper class that allows callers to specify more than one path for the desired library. The ordered, NULL-terminated array of paths is walked until loading one succeeds. The intention here is to support both versioned and unversioned file names for portability across operating systems with different library naming conventions, e.g: { libfoo.so.3, libfoo.so, DE_NULL } Should load "libfoo" on both Linux and BSD OSs. Components: Framework Change-Id: I1a0e1c055dd6eeee8e091be5148b99f1f63d86f6 --- framework/delibs/decpp/deDynamicLibrary.cpp | 11 +++++++++++ framework/delibs/decpp/deDynamicLibrary.hpp | 1 + 2 files changed, 12 insertions(+) diff --git a/framework/delibs/decpp/deDynamicLibrary.cpp b/framework/delibs/decpp/deDynamicLibrary.cpp index 2f8dadf..3284f9d 100644 --- a/framework/delibs/decpp/deDynamicLibrary.cpp +++ b/framework/delibs/decpp/deDynamicLibrary.cpp @@ -37,6 +37,17 @@ DynamicLibrary::DynamicLibrary (const char* fileName) throw std::runtime_error(std::string("Failed to open dynamic library: '") + fileName + "'"); } +DynamicLibrary::DynamicLibrary (const char* fileNames[]) + : m_library(DE_NULL) +{ + for (int i = 0; !m_library && fileNames[i]; i++) + { + m_library = deDynamicLibrary_open(fileNames[i]); + if (!m_library) + throw std::runtime_error(std::string("Failed to open dynamic library: '") + fileNames[0] + "'"); + } +} + DynamicLibrary::~DynamicLibrary (void) { deDynamicLibrary_close(m_library); diff --git a/framework/delibs/decpp/deDynamicLibrary.hpp b/framework/delibs/decpp/deDynamicLibrary.hpp index 788131d..4338344 100644 --- a/framework/delibs/decpp/deDynamicLibrary.hpp +++ b/framework/delibs/decpp/deDynamicLibrary.hpp @@ -36,6 +36,7 @@ class DynamicLibrary { public: DynamicLibrary (const char* fileName); + DynamicLibrary (const char* fileNames[]); ~DynamicLibrary (void); deFunctionPtr getFunction (const char* name) const { return deDynamicLibrary_getFunction(m_library, name); } -- 2.7.4