Plugin Management support C plugin
This commit is contained in:
40
src/plugin_manager/plugin_manager_util.cpp
Normal file
40
src/plugin_manager/plugin_manager_util.cpp
Normal file
@@ -0,0 +1,40 @@
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "plugin_manager_util.h"
|
||||
|
||||
char *safe_dup(const char *str)
|
||||
{
|
||||
if (str == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
char *dup = safe_alloc(char, strlen(str) + 1);
|
||||
memcpy(dup, str, strlen(str));
|
||||
|
||||
return dup;
|
||||
}
|
||||
|
||||
void strcat_prefix_and_file(const char *prefix, const char *file, char *buff, int size)
|
||||
{
|
||||
char prefix_buffer[4096] = {0};
|
||||
char file_buffer[4096] = {0};
|
||||
char *ptr = NULL;
|
||||
|
||||
memcpy(prefix_buffer, prefix, strlen(prefix));
|
||||
memcpy(file_buffer, file, strlen(file));
|
||||
|
||||
if (prefix_buffer[strlen(prefix_buffer) - 1] != '/')
|
||||
{
|
||||
prefix_buffer[strlen(prefix_buffer)] = '/';
|
||||
}
|
||||
file_buffer[strcspn(file_buffer, "\r\n")] = 0;
|
||||
|
||||
ptr = file_buffer;
|
||||
if (file_buffer[0] == '.' && file_buffer[1] == '/')
|
||||
{
|
||||
ptr += 2;
|
||||
}
|
||||
snprintf(buff, size, "%s%s", prefix_buffer, ptr);
|
||||
}
|
||||
Reference in New Issue
Block a user