micro-utils/libmu/make_path.h

28 lines
580 B
C

#ifndef _MAKE_PATH_H
#define _MAKE_PATH_H
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char *mu_make_path(const char *restrict prog_name, const char *restrict src, const char *restrict 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 (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