xtc/src/plugin/module_path.c
2026-11-06 18:13:49 +01:00

40 lines
1.4 KiB
C

#include "module_path.h"
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
xtc_result xtc_plugin_module_path(const char *path, char out[512])
{
struct stat status;
char resolved[512];
const char *name;
size_t length, stem;
int count;
if (!path || !out || path[0] != '/' || (length = strlen(path)) >= sizeof(resolved))
return XTC_ERR_INVALID_ARGUMENT;
if (stat(path, &status)) return XTC_ERR_NOT_FOUND;
if (S_ISREG(status.st_mode)) { memcpy(out, path, length + 1); return XTC_OK; }
if (!S_ISDIR(status.st_mode)) return XTC_ERR_UNSUPPORTED;
name = strrchr(path, '/') + 1;
stem = strlen(name);
if (stem <= 5 || strcmp(name + stem - 5, ".vst3")) return XTC_ERR_UNSUPPORTED;
#if defined(__x86_64__)
#define XTC_VST3_ARCH "x86_64-linux"
#elif defined(__aarch64__)
#define XTC_VST3_ARCH "aarch64-linux"
#elif defined(__i386__)
#define XTC_VST3_ARCH "i386-linux"
#elif defined(__arm__)
#define XTC_VST3_ARCH "arm-linux"
#else
return XTC_ERR_UNSUPPORTED;
#define XTC_VST3_ARCH "unsupported"
#endif
count = snprintf(resolved, sizeof(resolved), "%s/Contents/" XTC_VST3_ARCH "/%.*s.so",
path, (int)(stem - 5), name);
if (count < 0 || (size_t)count >= sizeof(resolved)) return XTC_ERR_INVALID_ARGUMENT;
if (stat(resolved, &status)) return XTC_ERR_NOT_FOUND;
if (!S_ISREG(status.st_mode)) return XTC_ERR_UNSUPPORTED;
memcpy(out, resolved, (size_t)count + 1);
return XTC_OK;
}