This commit is contained in:
Your Name 2024-07-09 11:02:46 +03:00
parent 7a048f8787
commit f8dd7660ae
143 changed files with 74 additions and 248 deletions

39
include/make_path.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef _MAKE_PATH_H
#define _MAKE_PATH_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *mu_make_path(const char *prog_name, const char *src, const char *dst) {
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;
}
#endif