2024-07-01 10:23:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2024-07-09 19:33:45 +00:00
|
|
|
char *mu_make_path(const char *prog_name, const char *src, const char *dst) {
|
2024-07-01 10:23:00 +00:00
|
|
|
int flag = 0;
|
|
|
|
|
|
|
|
if (src == NULL) {
|
|
|
|
flag = 1;
|
|
|
|
src = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dst == NULL) {
|
|
|
|
flag = 1;
|
|
|
|
dst = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t len = strlen(src) + strlen(dst) + 2;
|
|
|
|
char *full_path = malloc(len + 1);
|
|
|
|
if (full_path == NULL) {
|
|
|
|
if (prog_name != NULL)
|
|
|
|
fprintf(stderr, "%s: malloc() failed\n", prog_name);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flag || src[strlen(src) - 1] == '/')
|
|
|
|
snprintf(full_path, len, "%s%s", src, dst);
|
|
|
|
|
|
|
|
else
|
|
|
|
snprintf(full_path, len, "%s/%s", src, dst);
|
|
|
|
|
|
|
|
return full_path;
|
|
|
|
}
|