mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Refactor: move library functions and macros to own header
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/library.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
static void* libraryLoad(const char* path, int maxVersion)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef FF_INCLUDED_common_library
|
||||
#define FF_INCLUDED_common_library
|
||||
|
||||
#include <dlfcn.h>
|
||||
|
||||
#define FF_LIBRARY_SYMBOL(symbolName) \
|
||||
__typeof__(&symbolName) ff ## symbolName;
|
||||
|
||||
#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(symbolMapping == NULL) \
|
||||
{ \
|
||||
dlclose(library); \
|
||||
return returnValue; \
|
||||
}
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
|
||||
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, ff ## symbolName, symbolName, returnValue);
|
||||
|
||||
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...);
|
||||
|
||||
#endif
|
||||
@@ -1,8 +1,8 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/library.h"
|
||||
|
||||
#include <pthread.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
#define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \
|
||||
static dataObject data; \
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
#include <string.h>
|
||||
|
||||
#ifdef FF_HAVE_WAYLAND
|
||||
#include "common/library.h"
|
||||
#include <pthread.h>
|
||||
#include <dlfcn.h>
|
||||
#include <wayland-client.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include "displayServer.h"
|
||||
|
||||
#ifdef FF_HAVE_XCB
|
||||
#include "common/library.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <dlfcn.h>
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
typedef struct XcbPropertyData
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "displayServer.h"
|
||||
|
||||
#ifdef FF_HAVE_X11
|
||||
#include <dlfcn.h>
|
||||
#include "common/library.h"
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
typedef struct X11PropertyData
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define FF_DBUS_TIMEOUT_MILLISECONDS 35
|
||||
|
||||
#ifdef FF_HAVE_DBUS
|
||||
#include <dlfcn.h>
|
||||
#include "common/library.h"
|
||||
#include <dbus/dbus.h>
|
||||
|
||||
#define FF_DBUS_ITER_CONTINUE(iterator) \
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include <pthread.h>
|
||||
|
||||
#ifdef FF_HAVE_VULKAN
|
||||
#include "common/library.h"
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
static inline void applyVulkanVersion(uint32_t vulkanVersion, FFVersion* ffVersion)
|
||||
|
||||
@@ -385,25 +385,6 @@ typedef enum FFInitState
|
||||
FF_INITSTATE_FAILED = 2
|
||||
} FFInitState;
|
||||
|
||||
#define FF_LIBRARY_SYMBOL(symbolName) \
|
||||
__typeof__(&symbolName) ff ## symbolName;
|
||||
|
||||
#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(symbolMapping == NULL) \
|
||||
{ \
|
||||
dlclose(library); \
|
||||
return returnValue; \
|
||||
}
|
||||
|
||||
#define FF_LIBRARY_LOAD_SYMBOL(library, symbolName, returnValue) \
|
||||
__typeof__(&symbolName) FF_LIBRARY_LOAD_SYMBOL_ADRESS(library, ff ## symbolName, symbolName, returnValue);
|
||||
|
||||
//////////////////////
|
||||
// Common functions //
|
||||
//////////////////////
|
||||
@@ -487,9 +468,6 @@ int8_t ffVersionCompare(const FFVersion* version1, const FFVersion* version2);
|
||||
//common/processing.c
|
||||
void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]);
|
||||
|
||||
//common/libraries.c
|
||||
void* ffLibraryLoad(const FFstrbuf* userProvidedName, ...);
|
||||
|
||||
//common/networking.c
|
||||
void ffNetworkingGetHttp(const char* host, const char* path, uint32_t timeout, FFstrbuf* buffer);
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifdef FF_HAVE_IMAGEMAGICK6
|
||||
|
||||
#include "image.h"
|
||||
#include "common/library.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <magick/MagickCore.h>
|
||||
|
||||
static FF_LIBRARY_SYMBOL(ResizeImage);
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#ifdef FF_HAVE_IMAGEMAGICK7
|
||||
|
||||
#include "image.h"
|
||||
#include "common/library.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <MagickCore/MagickCore.h>
|
||||
|
||||
static FF_LIBRARY_SYMBOL(ResizeImage);
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#ifdef FF_HAVE_ZLIB
|
||||
#include "common/library.h"
|
||||
#include <stdlib.h>
|
||||
#include <dlfcn.h>
|
||||
#include <zlib.h>
|
||||
|
||||
static bool compressBlob(const FFinstance* instance, void** blob, size_t* length)
|
||||
|
||||
+1
-1
@@ -61,9 +61,9 @@ static void printGPUList(FFinstance* instance, const FFlist* list)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_LIBPCI
|
||||
#include "common/library.h"
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <dlfcn.h>
|
||||
#include <pci/pci.h>
|
||||
|
||||
//see https://github.com/pciutils/pciutils/blob/5bdf63b6b1bc35b59c4b3f47f7ca83ca1868155b/ls-kernel.c#L220
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#define FF_OPENCL_NUM_FORMAT_ARGS 3
|
||||
|
||||
#ifdef FF_HAVE_OPENCL
|
||||
#include <dlfcn.h>
|
||||
#include "common/library.h"
|
||||
|
||||
#define CL_TARGET_OPENCL_VERSION 100
|
||||
#include <CL/cl.h>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA)
|
||||
#define FF_HAVE_GL 1
|
||||
#include <dlfcn.h>
|
||||
#include "common/library.h"
|
||||
#include <GL/gl.h>
|
||||
|
||||
#define FF_OPENGL_BUFFER_WIDTH 1
|
||||
|
||||
@@ -130,7 +130,7 @@ static uint32_t getNixPackages(char* path)
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_RPM
|
||||
#include <dlfcn.h>
|
||||
#include "common/library.h"
|
||||
#include <rpm/rpmlib.h>
|
||||
#include <rpm/rpmts.h>
|
||||
#include <rpm/rpmdb.h>
|
||||
|
||||
Reference in New Issue
Block a user