Look for different versions of the same library

This commit is contained in:
Linus Dierheimer
2022-01-05 16:14:27 +01:00
parent 59e61f53e1
commit 53f31f2401
9 changed files with 50 additions and 20 deletions
+1
View File
@@ -163,6 +163,7 @@ set(SRCS
src/common/format.c
src/common/parsing.c
src/common/settings.c
src/common/library.c
src/detection/plasma.c
src/detection/gtk.c
src/detection/terminalShell.c
+27
View File
@@ -0,0 +1,27 @@
#include "fastfetch.h"
#include <stdarg.h>
//common/libraries.c
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...)
{
if(userProvidedName->length > 0)
return dlopen(userProvidedName->chars, RTLD_LAZY);
va_list defaultNames;
va_start(defaultNames, userProvidedName);
void* result = NULL;
while(result == NULL)
{
const char* name = va_arg(defaultNames, const char*);
if(name == NULL)
break;
result = dlopen(name, RTLD_LAZY);
}
va_end(defaultNames);
return result;
}
+7 -7
View File
@@ -5,7 +5,7 @@
#ifdef FF_HAVE_GIO
#include <gio/gio.h>
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, libraryName, userLibraryName) \
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
static dataObject data; \
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; \
static FFInitState initState = FF_INITSTATE_UNINITIALIZED; \
@@ -15,8 +15,8 @@
return initState == FF_INITSTATE_SUCCESSFUL ? &data : NULL; \
} \
initState = FF_INITSTATE_SUCCESSFUL; \
void* libraryHandle = dlopen(userLibraryName.length == 0 ? libraryName : userLibraryName.chars, RTLD_LAZY); \
if(dlerror() != NULL || libraryHandle == NULL) { \
void* libraryHandle = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL); \
if(libraryHandle == NULL) { \
initState = FF_INITSTATE_FAILED; \
pthread_mutex_unlock(&mutex); \
return NULL; \
@@ -24,7 +24,7 @@
#define FF_LIBRARY_DATA_LOAD_SYMBOL(symbolName) \
data.ff ## symbolName = dlsym(libraryHandle, #symbolName); \
if(dlerror() != NULL || data.ff ## symbolName == NULL) { \
if(data.ff ## symbolName == NULL) { \
dlclose(libraryHandle); \
initState = FF_INITSTATE_FAILED; \
pthread_mutex_unlock(&mutex); \
@@ -80,7 +80,7 @@ typedef struct GSettingsData
static const GSettingsData* getGSettingsData(FFinstance* instance)
{
FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, "libgio-2.0.so", instance->config.libGIO)
FF_LIBRARY_DATA_LOAD_INIT(GSettingsData, instance->config.libGIO, "libgio-2.0.so", "libgio-2.0.so.0");
FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_source_lookup)
FF_LIBRARY_DATA_LOAD_SYMBOL(g_settings_schema_has_key)
@@ -152,7 +152,7 @@ typedef struct DConfData
static const DConfData* getDConfData(FFinstance* instance)
{
FF_LIBRARY_DATA_LOAD_INIT(DConfData, "libdconf.so", instance->config.libDConf)
FF_LIBRARY_DATA_LOAD_INIT(DConfData, instance->config.libDConf, "libdconf.so", "libdconf.so.1");
FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_read_full)
FF_LIBRARY_DATA_LOAD_SYMBOL(dconf_client_new)
@@ -222,7 +222,7 @@ typedef struct XFConfData
static const XFConfData* getXFConfData(FFinstance* instance)
{
FF_LIBRARY_DATA_LOAD_INIT(XFConfData, "libxfconf-0.so", instance->config.libXFConf)
FF_LIBRARY_DATA_LOAD_INIT(XFConfData, instance->config.libXFConf, "libxfconf-0.so", "libxfconf-0.so.3");
FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_get)
FF_LIBRARY_DATA_LOAD_SYMBOL(xfconf_channel_has_property)
+1 -1
View File
@@ -78,7 +78,7 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul
if(getenv("XDG_RUNTIME_DIR") == NULL)
return;
FF_LIBRARY_LOAD(wayland, "libwayland-client.so", instance->config.libWayland,);
FF_LIBRARY_LOAD(wayland, instance->config.libWayland, , "libwayland-client.so", "libwayland-client.so.0")
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect,)
FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch,)
+2 -2
View File
@@ -89,7 +89,7 @@ static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connect
void ffdsConnectXcb(const FFinstance* instance, FFDisplayServerResult* result)
{
FF_LIBRARY_LOAD(xcb, "libxcb.so", instance->config.libXcb,)
FF_LIBRARY_LOAD(xcb, instance->config.libXcb, , "libxcb.so", "libxcb.so.1")
FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_connect,)
FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_get_setup,)
FF_LIBRARY_LOAD_SYMBOL(xcb, xcb_setup_roots_iterator,)
@@ -324,7 +324,7 @@ static void xcbRandrHandleScreen(XcbRandrData* data, xcb_screen_t* screen)
void ffdsConnectXcbRandr(const FFinstance* instance, FFDisplayServerResult* result)
{
FF_LIBRARY_LOAD(xcbRandr, "libxcb-randr.so", instance->config.libXcbRandr,)
FF_LIBRARY_LOAD(xcbRandr, instance->config.libXcbRandr, , "libxcb-randr.so", "libxcb-randr.so.0")
FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_connect,)
FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_get_setup,)
FF_LIBRARY_LOAD_SYMBOL(xcbRandr, xcb_setup_roots_iterator,)
+2 -2
View File
@@ -52,7 +52,7 @@ static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDispl
void ffdsConnectXlib(const FFinstance* instance, FFDisplayServerResult* result)
{
FF_LIBRARY_LOAD(x11, "libX11.so", instance->config.libX11,)
FF_LIBRARY_LOAD(x11, instance->config.libX11, , "libX11.so", "libX11.so.6", "libX11-xcb.so", "libX11-xcb.so.1")
FF_LIBRARY_LOAD_SYMBOL(x11, XOpenDisplay,)
FF_LIBRARY_LOAD_SYMBOL(x11, XCloseDisplay,)
@@ -256,7 +256,7 @@ static void xrandrHandleScreen(XrandrData* data, Screen* screen)
void ffdsConnectXrandr(const FFinstance* instance, FFDisplayServerResult* result)
{
FF_LIBRARY_LOAD(xrandr, "libXrandr.so", instance->config.libXrandr,);
FF_LIBRARY_LOAD(xrandr, instance->config.libXrandr, , "libXrandr.so", "libXrandr.so.2")
FF_LIBRARY_LOAD_SYMBOL(xrandr, XOpenDisplay,)
FF_LIBRARY_LOAD_SYMBOL(xrandr, XCloseDisplay,)
+7 -4
View File
@@ -292,14 +292,14 @@ typedef enum FFInitState
#define FF_LIBRARY_SYMBOL(symbolName) \
__typeof__(&symbolName) ff ## symbolName;
#define FF_LIBRARY_LOAD(libraryObjectName, libraryName, userLibraryName, returnValue) \
void* libraryObjectName = dlopen(userLibraryName.length == 0 ? libraryName : userLibraryName.chars, RTLD_LAZY); \
if(dlerror() != NULL || libraryObjectName == NULL) \
#define FF_LIBRARY_LOAD(libraryObjectName, userLibraryName, returnValue, ...) \
void* libraryObjectName = ffLibraryLoad(&userLibraryName, __VA_ARGS__, NULL);\
if(libraryObjectName == NULL) \
return returnValue;
#define FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, symbolMapping, symbolName, returnValue) \
symbolMapping = dlsym(library, #symbolName); \
if(dlerror() != NULL || symbolMapping == NULL) \
if(symbolMapping == NULL) \
{ \
dlclose(library); \
return returnValue; \
@@ -359,6 +359,9 @@ bool ffParsePropFileConfig(const FFinstance* instance, const char* relativeFile,
//common/processing.c
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]);
//common/libraries.c
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...);
//common/logo.c
void ffLoadLogoSet(FFinstance* instance, const char* logo);
void ffLoadLogo(FFinstance* instance);
+2 -3
View File
@@ -16,7 +16,7 @@ typedef struct GPUResult
static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
{
FF_LIBRARY_LOAD(vulkan, "libvulkan.so", instance->config.libVulkan,)
FF_LIBRARY_LOAD(vulkan, instance->config.libVulkan, , "libvulkan.so", "libvulkan.so.1")
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkCreateInstance,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkDestroyInstance,)
FF_LIBRARY_LOAD_SYMBOL(vulkan, vkEnumeratePhysicalDevices,)
@@ -104,8 +104,7 @@ static void vulkanFillGPUs(FFinstance* instance, FFlist* results)
static void pciFillGPUs(FFinstance* instance, FFlist* results)
{
FF_LIBRARY_LOAD(pci, "libpci.so", instance->config.libPCI,)
FF_LIBRARY_LOAD(pci, instance->config.libPCI, , "libpci.so", "libpci.so.3")
FF_LIBRARY_LOAD_SYMBOL(pci, pci_alloc,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_init,)
FF_LIBRARY_LOAD_SYMBOL(pci, pci_scan_bus,)
+1 -1
View File
@@ -14,7 +14,7 @@
static uint32_t getRpmPackageCount(FFinstance* instance)
{
FF_LIBRARY_LOAD(rpm, "librpm.so", instance->config.librpm, 0);
FF_LIBRARY_LOAD(rpm, instance->config.libRpm, 0, "librpm.so", "librpm.so.4")
FF_LIBRARY_LOAD_SYMBOL(rpm, rpmReadConfigFiles, 0)
FF_LIBRARY_LOAD_SYMBOL(rpm, rpmtsCreate, 0)
FF_LIBRARY_LOAD_SYMBOL(rpm, rpmtsInitIterator, 0)