X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftal%2Fpath%2Fpath.c;h=362152d29cb261747f60a46d14db60addd6b928b;hp=0ad168c872d219d3b485e23d53d39ab430d40eb7;hb=ed6dd33e06c0e8f1c4dd006e0b70d9f2d6ba6c09;hpb=892f59bdc1830443f87ad3aaeddaab2eeefb5937 diff --git a/ccan/tal/path/path.c b/ccan/tal/path/path.c index 0ad168c8..362152d2 100644 --- a/ccan/tal/path/path.c +++ b/ccan/tal/path/path.c @@ -1,7 +1,6 @@ /* Licensed under BSD-MIT - see LICENSE file for details */ #include #include -#include #include #include #include @@ -50,7 +49,7 @@ char *path_join(const tal_t *ctx, const char *base, const char *a) goto out; len = strlen(base); - ret = tal_dup(ctx, char, base, len, 1 + strlen(a) + 1); + ret = tal_dup_arr(ctx, char, base, len, 1 + strlen(a) + 1); if (!ret) goto out; if (ret[len-1] != PATH_SEP) @@ -244,8 +243,10 @@ char *path_rel(const tal_t *ctx, const char *from, const char *to) /* This frees to if we're supposed to take it. */ cto = path_canon(tmpctx, to); - if (!cto) + if (!cto) { + ret = NULL; goto out; + } /* How much is in common? */ for (common = i = 0; cfrom[i] && cto[i]; i++) { @@ -323,7 +324,9 @@ fail_take_to: goto fail; } - ret[len] = '\0'; + if (ret) + ret[len] = '\0'; + out: if (taken(linkname)) tal_free(linkname); @@ -461,7 +464,7 @@ char *path_basename(const tal_t *ctx, const char *path) static char *fixed_string(const tal_t *ctx, const char *str, const char *path) { - char *ret = tal_dup(ctx, char, path, 0, strlen(str)+1); + char *ret = tal_dup_arr(ctx, char, path, 0, strlen(str)+1); if (ret) strcpy(ret, str); return ret; @@ -525,7 +528,7 @@ bool path_is_dir(const char *path) char **path_split(const tal_t *ctx, const char *path) { bool empty = path && !path[0]; - char **ret = strsplit(ctx, path, PATH_SEP_STR, STR_NO_EMPTY); + char **ret = tal_strsplit(ctx, path, PATH_SEP_STR, STR_NO_EMPTY); /* Handle the "/" case */ if (ret && !empty && !ret[0]) {