From 542edc8b0c5f7fb9d0309484e2697c594a049fe7 Mon Sep 17 00:00:00 2001 From: mrwastl Date: Tue, 6 Mar 2012 21:21:29 +0100 Subject: more flexible including of serdisplib in dlopen() --- glcddrivers/serdisp.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/glcddrivers/serdisp.c b/glcddrivers/serdisp.c index 8c29ede..8b46bcb 100644 --- a/glcddrivers/serdisp.c +++ b/glcddrivers/serdisp.c @@ -7,7 +7,7 @@ * This file is released under the GNU General Public License. Refer * to the COPYING file distributed with this package. * - * (c) 2003-2011 Wolfgang Astleitner + * (c) 2003-2012 Wolfgang Astleitner */ #include @@ -61,10 +61,27 @@ int cDriverSerDisp::Init(void) std::string optionstring = ""; std::string wiringstring; + int chk_major = 0; + std::string libname = ""; // dynamically load serdisplib using dlopen() & co. + sdhnd = NULL; + chk_major = 3; // max major version to check + + while ( ! sdhnd && chk_major > 0) { + libname = "libserdisp.so."; + libname.push_back (chk_major + '0'); + sdhnd = dlopen(libname.c_str(), RTLD_LAZY); + if (!sdhnd) { // try /usr/local/lib + libname.insert(0, "/usr/local/lib/"); + sdhnd = dlopen(libname.c_str(), RTLD_LAZY); + } + chk_major --; + } - sdhnd = dlopen("libserdisp.so", RTLD_LAZY); + if (!sdhnd) { // try libserdisp.so without major version + sdhnd = dlopen("libserdisp.so", RTLD_LAZY); + } if (!sdhnd) { // try /usr/local/lib sdhnd = dlopen("/usr/local/lib/libserdisp.so", RTLD_LAZY); } -- cgit v1.2.3