fix: resolve Windows segfaults by using platform-specific path separators
On Windows, module IDs were failing to load because paths were being constructed with hardcoded forward slashes. Oops... - Added platform.h to centralize path separator macros. - Updated build_path in stk.c to use STK_PATH_SEP_STR instead of "/". - Cleaned up redundant platform logic in module.c.
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
#ifndef STK_PLATFORM_H
|
||||
#define STK_PLATFORM_H
|
||||
|
||||
#ifdef _WIN32
|
||||
#define STK_PATH_SEP '\\'
|
||||
#define STK_PATH_SEP_STR "\\"
|
||||
#else
|
||||
#define STK_PATH_SEP '/'
|
||||
#define STK_PATH_SEP_STR "/"
|
||||
#endif
|
||||
|
||||
#endif /* STK_PLATFORM_H */
|
||||
+1
-6
@@ -1,3 +1,4 @@
|
||||
#include "platform.h"
|
||||
#include "stk.h"
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
@@ -5,12 +6,6 @@
|
||||
|
||||
#define STK_MOD_FUNC_NAME_BUFFER 64
|
||||
|
||||
#ifdef _WIN32
|
||||
#define STK_PATH_SEP '\\'
|
||||
#else
|
||||
#define STK_PATH_SEP '/'
|
||||
#endif
|
||||
|
||||
typedef int (*stk_init_mod_func)(void);
|
||||
typedef void (*stk_shutdown_mod_func)(void);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "stk.h"
|
||||
#include "platform.h"
|
||||
#include "stk_log.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
@@ -49,7 +50,7 @@ static void build_path(char *dest, size_t dest_size, const char *dir,
|
||||
{
|
||||
dest[0] = '\0';
|
||||
strncat(dest, dir, dest_size - 1);
|
||||
strncat(dest, "/", dest_size - strlen(dest) - 1);
|
||||
strncat(dest, STK_PATH_SEP_STR, dest_size - strlen(dest) - 1);
|
||||
strncat(dest, file, dest_size - strlen(dest) - 1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user