feat: make module paths and entry points configurable

* Added functions to set mod dir, temp dir name, and module init/shutdown function names.
* Replaced hardcoded string literals with configurable static buffers in module.c.
* Improved string safety by replacing sprintf with strncpy/strncat.
* Updated stk_init local path buffers to handle maximum combined path lengths.
This commit is contained in:
2026-01-25 16:52:52 +01:00
parent ac0125274d
commit 472cb3b163
3 changed files with 76 additions and 13 deletions
+26 -2
View File
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <string.h>
#define STK_MOD_FUNC_NAME_BUFFER 64
void *platform_load_library(const char *path);
void platform_unload_library(void *handle);
void *platform_get_symbol(void *handle, const char *symbol);
@@ -14,6 +16,10 @@ void **stk_handles = NULL;
stk_module_func *stk_inits = NULL;
stk_module_func *stk_shutdowns = NULL;
static char stk_mod_init_name[STK_MOD_FUNC_NAME_BUFFER] = "stk_mod_init";
static char stk_mod_shutdown_name[STK_MOD_FUNC_NAME_BUFFER] =
"stk_mod_shutdown";
size_t module_count = 0;
size_t stk_module_count(void) { return module_count; }
@@ -108,10 +114,10 @@ int stk_module_load(const char *path, int index)
if (!handle)
return -1;
u.obj = platform_get_symbol(handle, "stk_module_init");
u.obj = platform_get_symbol(handle, stk_mod_init_name);
init_func = u.func;
u.obj = platform_get_symbol(handle, "stk_module_shutdown");
u.obj = platform_get_symbol(handle, stk_mod_shutdown_name);
shutdown_func = u.func;
if (!init_func || !shutdown_func) {
@@ -200,3 +206,21 @@ void stk_module_unload_all(void)
stk_module_free_memory();
}
void stk_set_module_init_fn(const char *name)
{
if (!name)
return;
strncpy(stk_mod_init_name, name, STK_MOD_FUNC_NAME_BUFFER - 1);
stk_mod_init_name[STK_MOD_FUNC_NAME_BUFFER - 1] = '\0';
}
void stk_set_module_shutdown_fn(const char *name)
{
if (!name)
return;
strncpy(stk_mod_shutdown_name, name, STK_MOD_FUNC_NAME_BUFFER - 1);
stk_mod_shutdown_name[STK_MOD_FUNC_NAME_BUFFER - 1] = '\0';
}