mktemp and make_path.h fixed
This commit is contained in:
parent
76d1f36797
commit
cc03a9f1f6
|
@ -6,6 +6,18 @@
|
|||
#include <stdlib.h>
|
||||
|
||||
char *mu_make_path(const char *restrict prog_name, const char *restrict src, const char *restrict 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) {
|
||||
|
@ -15,7 +27,7 @@ char *mu_make_path(const char *restrict prog_name, const char *restrict src, con
|
|||
return NULL;
|
||||
}
|
||||
|
||||
if (src[strlen(src) - 1] == '/')
|
||||
if (flag || src[strlen(src) - 1] == '/')
|
||||
snprintf(full_path, len, "%s%s", src, dst);
|
||||
|
||||
else
|
||||
|
|
|
@ -68,7 +68,7 @@ int main(int argc, char **argv) {
|
|||
argv += optind;
|
||||
argc -= optind;
|
||||
|
||||
if (path == NULL) {
|
||||
if (argc == 0 && path == NULL) {
|
||||
path = getenv("TMPDIR");
|
||||
if (!path || path[0] == '\0')
|
||||
path = "/tmp/";
|
||||
|
|
Loading…
Reference in New Issue