summaryrefslogtreecommitdiff
path: root/src/plugins/plugin_manager.c
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-16 00:19:37 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-16 00:19:37 +0000
commit23d18925df02157e9330c3612992e40553bb5da1 (patch)
tree89a893944aa7555c59b7700aa608f39680c0a120 /src/plugins/plugin_manager.c
parent301d9582884ec7d180791e5c9c6ec649dc01ff68 (diff)
Working on reducing function pollution
Diffstat (limited to 'src/plugins/plugin_manager.c')
-rw-r--r--src/plugins/plugin_manager.c135
1 files changed, 59 insertions, 76 deletions
diff --git a/src/plugins/plugin_manager.c b/src/plugins/plugin_manager.c
index afca55e..aab98c8 100644
--- a/src/plugins/plugin_manager.c
+++ b/src/plugins/plugin_manager.c
@@ -6,99 +6,82 @@
#include <string.h>
// Linked list node for plugins.
-typedef struct PluginNode
-{
- ZPlugin *plugin;
- void *handle; // dlopen handle (NULL for built-ins).
- struct PluginNode *next;
+typedef struct PluginNode {
+ ZPlugin *plugin;
+ void *handle; // dlopen handle (NULL for built-ins).
+ struct PluginNode *next;
} PluginNode;
static PluginNode *head = NULL;
-void zptr_plugin_mgr_init(void)
-{
- head = NULL;
-}
+void zptr_plugin_mgr_init(void) { head = NULL; }
-void zptr_register_plugin(ZPlugin *plugin)
-{
- if (!plugin)
- {
- return;
- }
+void zptr_register_plugin(ZPlugin *plugin) {
+ if (!plugin) {
+ return;
+ }
- if (zptr_find_plugin(plugin->name))
- {
- return;
- }
+ if (zptr_find_plugin(plugin->name)) {
+ return;
+ }
- PluginNode *node = malloc(sizeof(PluginNode));
- node->plugin = plugin;
- node->handle = NULL;
- node->next = head;
- head = node;
+ PluginNode *node = malloc(sizeof(PluginNode));
+ node->plugin = plugin;
+ node->handle = NULL;
+ node->next = head;
+ head = node;
}
-ZPlugin *zptr_load_plugin(const char *path)
-{
- void *handle = dlopen(path, RTLD_LAZY);
- if (!handle)
- {
- return NULL;
- }
+ZPlugin *zptr_load_plugin(const char *path) {
+ void *handle = dlopen(path, RTLD_LAZY);
+ if (!handle) {
+ return NULL;
+ }
- ZPluginInitFn init_fn = (ZPluginInitFn)dlsym(handle, "z_plugin_init");
- if (!init_fn)
- {
- fprintf(stderr, "Plugin '%s' missing 'z_plugin_init' symbol\n", path);
- dlclose(handle);
- return NULL;
- }
+ ZPluginInitFn init_fn = (ZPluginInitFn)dlsym(handle, "z_plugin_init");
+ if (!init_fn) {
+ fprintf(stderr, "Plugin '%s' missing 'z_plugin_init' symbol\n", path);
+ dlclose(handle);
+ return NULL;
+ }
- ZPlugin *plugin = init_fn();
- if (!plugin)
- {
- fprintf(stderr, "Plugin '%s' init returned NULL\n", path);
- dlclose(handle);
- return NULL;
- }
+ ZPlugin *plugin = init_fn();
+ if (!plugin) {
+ fprintf(stderr, "Plugin '%s' init returned NULL\n", path);
+ dlclose(handle);
+ return NULL;
+ }
- // Register
- PluginNode *node = malloc(sizeof(PluginNode));
- node->plugin = plugin;
- node->handle = handle;
- node->next = head;
- head = node;
+ // Register
+ PluginNode *node = malloc(sizeof(PluginNode));
+ node->plugin = plugin;
+ node->handle = handle;
+ node->next = head;
+ head = node;
- return plugin;
+ return plugin;
}
-ZPlugin *zptr_find_plugin(const char *name)
-{
- PluginNode *curr = head;
- while (curr)
- {
- if (strcmp(curr->plugin->name, name) == 0)
- {
- return curr->plugin;
- }
- curr = curr->next;
+ZPlugin *zptr_find_plugin(const char *name) {
+ PluginNode *curr = head;
+ while (curr) {
+ if (strcmp(curr->plugin->name, name) == 0) {
+ return curr->plugin;
}
- return NULL;
+ curr = curr->next;
+ }
+ return NULL;
}
-void zptr_plugin_mgr_cleanup(void)
-{
- PluginNode *curr = head;
- while (curr)
- {
- PluginNode *next = curr->next;
- if (curr->handle)
- {
- dlclose(curr->handle);
- }
- free(curr);
- curr = next;
+void zptr_plugin_mgr_cleanup(void) {
+ PluginNode *curr = head;
+ while (curr) {
+ PluginNode *next = curr->next;
+ if (curr->handle) {
+ dlclose(curr->handle);
}
- head = NULL;
+ free(curr);
+ curr = next;
+ }
+ head = NULL;
}