This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/src/plugin_manager/plugin_manager_util.cpp

40 lines
809 B
C++
Raw Normal View History

2022-07-27 18:32:22 +08:00
#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);
}