Skip to content

Commit 8831c07

Browse files
Look for multiple versions of a library
1 parent e009bb1 commit 8831c07

File tree

10 files changed

+48
-18
lines changed

10 files changed

+48
-18
lines changed

src/common/library.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
#include <stdarg.h>
44

5+
static void* libraryLoad(const char* path, int maxVersion)
6+
{
7+
void* result = dlopen(path, RTLD_LAZY);
8+
if(result != NULL)
9+
return result;
10+
11+
FFstrbuf pathbuf;
12+
ffStrbufInitA(&pathbuf, 64);
13+
ffStrbufAppendS(&pathbuf, path);
14+
ffStrbufAppendC(&pathbuf, '.');
15+
16+
for(int i = maxVersion; i >= 0; --i)
17+
{
18+
uint32_t originalLength = pathbuf.length;
19+
ffStrbufAppendF(&pathbuf, "%i", i);
20+
21+
result = dlopen(pathbuf.chars, RTLD_LAZY);
22+
if(result != NULL)
23+
break;
24+
25+
ffStrbufSubstrBefore(&pathbuf, originalLength);
26+
}
27+
28+
ffStrbufDestroy(&pathbuf);
29+
return result;
30+
}
31+
532
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...)
633
{
734
if(userProvidedName->length > 0)
@@ -11,12 +38,15 @@ void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...)
1138
va_start(defaultNames, userProvidedName);
1239

1340
void* result = NULL;
14-
const char* name = va_arg(defaultNames, const char*);
1541

16-
while(result == NULL && name != NULL)
42+
while(result == NULL)
1743
{
18-
result = dlopen(name, RTLD_LAZY);
19-
name = va_arg(defaultNames, const char*);
44+
const char* path = va_arg(defaultNames, const char*);
45+
if(path == NULL)
46+
break;
47+
48+
int maxVersion = va_arg(defaultNames, int);
49+
result = libraryLoad(path, maxVersion);
2050
}
2151

2252
va_end(defaultNames);

src/common/settings.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ typedef struct GSettingsData
8080

8181
static const GSettingsData* getGSettingsData(FFinstance* instance)
8282
{
83-
FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, instance->config.libGIO, "libgio-2.0.so", "libgio-2.0.so.0");
83+
FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, instance->config.libGIO, "libgio-2.0.so", 1);
8484

8585
FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_source_lookup)
8686
FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_has_key)
@@ -152,7 +152,7 @@ typedef struct DConfData
152152

153153
static const DConfData* getDConfData(FFinstance* instance)
154154
{
155-
FF_LIBRARY_DATA_LOAD_INIT(DConfData, instance->config.libDConf, "libdconf.so", "libdconf.so.1");
155+
FF_LIBRARY_DATA_LOAD_INIT(DConfData, instance->config.libDConf, "libdconf.so", 2);
156156

157157
FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_read_full)
158158
FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_new)
@@ -222,7 +222,7 @@ typedef struct XFConfData
222222

223223
static const XFConfData* getXFConfData(FFinstance* instance)
224224
{
225-
FF_LIBRARY_DATA_LOAD_INIT(XFConfData, instance->config.libXFConf, "libxfconf-0.so", "libxfconf-0.so.3");
225+
FF_LIBRARY_DATA_LOAD_INIT(XFConfData, instance->config.libXFConf, "libxfconf-0.so", 4);
226226

227227
FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get)
228228
FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_has_property)

src/detection/displayserver/wayland.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul
7878
if(getenv("XDG_RUNTIME_DIR") == NULL)
7979
return;
8080

81-
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, , "libwayland-client.so", "libwayland-client.so.0")
81+
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, , "libwayland-client.so", 1)
8282

8383
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect,)
8484
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch,)

src/detection/displayserver/xcb.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connect
8989

9090
void ffdsConnectXcb(const FFinstance* instance, FFDisplayServerResult* result)
9191
{
92-
FF_LIBRARY_LOAD(xcb, instance->config.libXcb, , "libxcb.so", "libxcb.so.1")
92+
FF_LIBRARY_LOAD(xcb, instance->config.libXcb, , "libxcb.so", 2)
9393
FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_connect,)
9494
FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_get_setup,)
9595
FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_setup_roots_iterator,)
@@ -324,7 +324,7 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
324324

325325
void ffdsConnectXcbRandr(const FFinstance* instance, FFDisplayServerResult* result)
326326
{
327-
FF_LIBRARY_LOAD(xcbRandr, instance->config.libXcbRandr, , "libxcb-randr.so", "libxcb-randr.so.0")
327+
FF_LIBRARY_LOAD(xcbRandr, instance->config.libXcbRandr, , "libxcb-randr.so", 1)
328328
FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_connect,)
329329
FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_get_setup,)
330330
FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_setup_roots_iterator,)

src/detection/displayserver/xlib.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDispl
5353

5454
void ffdsConnectXlib(const FFinstance* instance, FFDisplayServerResult* result)
5555
{
56-
FF_LIBRARY_LOAD(x11, instance->config.libX11, , "libX11.so", "libX11.so.6", "libX11-xcb.so", "libX11-xcb.so.1")
56+
FF_LIBRARY_LOAD(x11, instance->config.libX11, , "libX11.so", 7, "libX11-xcb.so", 2)
5757
FF_LIBRARY_LOAD_SYMBOL(x11, XOpenDisplay,)
5858
FF_LIBRARY_LOAD_SYMBOL(x11, XCloseDisplay,)
5959

@@ -257,7 +257,7 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
257257

258258
void ffdsConnectXrandr(const FFinstance* instance, FFDisplayServerResult* result)
259259
{
260-
FF_LIBRARY_LOAD(xrandr, instance->config.libXrandr, , "libXrandr.so", "libXrandr.so.2")
260+
FF_LIBRARY_LOAD(xrandr, instance->config.libXrandr, , "libXrandr.so", 3)
261261

262262
FF_LIBRARY_LOAD_SYMBOL(xrandr, XOpenDisplay,)
263263
FF_LIBRARY_LOAD_SYMBOL(xrandr, XCloseDisplay,)

src/detection/media.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static void getMedia(FFinstance* instance, FFMediaResult* result)
285285
{
286286
DBusData data;
287287

288-
FF_LIBRARY_LOAD(dbus, instance->config.libDBus, , "libdbus-1.so", "libdbus-1.so.3");
288+
FF_LIBRARY_LOAD(dbus, instance->config.libDBus, , "libdbus-1.so", 4);
289289
FF_LIBRARY_LOAD_SYMBOL(dbus, dbus_bus_get,)
290290
FF_LIBRARY_LOAD_SYMBOL_ADRESS(dbus, data.ffdbus_message_new_method_call, dbus_message_new_method_call,)
291291
FF_LIBRARY_LOAD_SYMBOL_ADRESS(dbus, data.ffdbus_message_iter_init, dbus_message_iter_init,)

src/logo/sixel/im6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ static bool logoWriteIM6(void* image, const void* imageInfo, void* exceptionInfo
2020

2121
bool ffLogoPrintSixelIM6(FFinstance* instance)
2222
{
23-
FF_LIBRARY_LOAD(imageMagick, instance->config.libImageMagick, "libMagickCore-6.Q16HDRI.so", "libMagickCore-6.Q16HDRI.so.6", "libMagickCore-6.Q16.so", "libMagickCore-6.Q16.so.6")
23+
FF_LIBRARY_LOAD(imageMagick, instance->config.libImageMagick, false, "libMagickCore-6.Q16HDRI.so", 8, "libMagickCore-6.Q16.so", 8)
2424

2525
FF_LIBRARY_LOAD_SYMBOL_ADRESS(imageMagick, ffResizeImage, ResizeImage, false);
2626
FF_LIBRARY_LOAD_SYMBOL_ADRESS(imageMagick, ffWriteImage, WriteImage, false);

src/logo/sixel/im7.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static bool logoWriteIM7(void* image, const void* imageInfo, void* exceptionInfo
1919

2020
bool ffLogoPrintSixelIM7(FFinstance* instance)
2121
{
22-
FF_LIBRARY_LOAD(imageMagick, instance->config.libImageMagick, "libMagickCore-7.Q16HDRI.so", "libMagickCore-7.Q16HDRI.so.10", "libMagickCore-7.Q16.so", "libMagickCore-7.Q16.so.10")
22+
FF_LIBRARY_LOAD(imageMagick, instance->config.libImageMagick, false, "libMagickCore-7.Q16HDRI.so", 11, "libMagickCore-7.Q16.so", 11)
2323

2424
FF_LIBRARY_LOAD_SYMBOL_ADRESS(imageMagick, ffResizeImage, ResizeImage, false);
2525
FF_LIBRARY_LOAD_SYMBOL_ADRESS(imageMagick, ffWriteImage, WriteImage, false);

src/modules/gpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ typedef struct GPUResult
1717

1818
static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
1919
{
20-
FF_LIBRARY_LOAD(vulkan, instance->config.libVulkan, , "libvulkan.so", "libvulkan.so.1")
20+
FF_LIBRARY_LOAD(vulkan, instance->config.libVulkan, , "libvulkan.so", 2)
2121
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkCreateInstance,)
2222
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkDestroyInstance,)
2323
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkEnumeratePhysicalDevices,)
@@ -133,7 +133,7 @@ static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get
133133

134134
static void pciFillGPUs(FFinstance* instance, FFlist* results)
135135
{
136-
FF_LIBRARY_LOAD(pci, instance->config.libPCI, , "libpci.so", "libpci.so.3")
136+
FF_LIBRARY_LOAD(pci, instance->config.libPCI, , "libpci.so", 4)
137137
FF_LIBRARY_LOAD_SYMBOL(pci, pci_alloc,)
138138
FF_LIBRARY_LOAD_SYMBOL(pci, pci_init,)
139139
FF_LIBRARY_LOAD_SYMBOL(pci, pci_scan_bus,)

src/modules/packages.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
static uint32_t getRpmPackageCount(FFinstance* instance)
1616
{
17-
FF_LIBRARY_LOAD(rpm, instance->config.librpm, 0, "librpm.so", "librpm.so.4")
17+
FF_LIBRARY_LOAD(rpm, instance->config.librpm, 0, "librpm.so", 5)
1818
FF_LIBRARY_LOAD_SYMBOL(rpm, rpmReadConfigFiles, 0)
1919
FF_LIBRARY_LOAD_SYMBOL(rpm, rpmtsCreate, 0)
2020
FF_LIBRARY_LOAD_SYMBOL(rpm, rpmtsInitIterator, 0)

0 commit comments

Comments
 (0)