From c6d44836fd8ed1442e01825cb0f9f97e7bf11515 Mon Sep 17 00:00:00 2001 From: David Moc Date: Wed, 3 Jun 2026 02:26:11 +0200 Subject: Harden editor logging and packaging --- src/path.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/path.c') diff --git a/src/path.c b/src/path.c index 1e002d7..be2b347 100644 --- a/src/path.c +++ b/src/path.c @@ -1,5 +1,7 @@ #include "path.h" +#include "util.h" + #include #include #include @@ -25,16 +27,12 @@ int ecex_path_copy(char *out, size_t out_size, const char *text) { char *ecex_path_expand_user(const char *path) { if (!path) return NULL; if (path[0] != '~' || (path[1] != '\0' && path[1] != '/')) { - char *copy = malloc(strlen(path) + 1); - if (copy) strcpy(copy, path); - return copy; + return ecex_strdup(path); } const char *home = getenv("HOME"); if (!home || !home[0]) { - char *copy = malloc(strlen(path) + 1); - if (copy) strcpy(copy, path); - return copy; + return ecex_strdup(path); } size_t home_len = strlen(home); @@ -49,9 +47,7 @@ char *ecex_path_expand_user(const char *path) { char *ecex_path_join(const char *dir, const char *name) { if (!name) return NULL; if (name[0] == '/') { - char *copy = malloc(strlen(name) + 1); - if (copy) strcpy(copy, name); - return copy; + return ecex_strdup(name); } if (!dir || !dir[0]) dir = "."; @@ -68,9 +64,7 @@ char *ecex_path_join(const char *dir, const char *name) { char *ecex_path_dirname(const char *path) { if (!path || !path[0]) { - char *dot = malloc(2); - if (dot) strcpy(dot, "."); - return dot; + return ecex_strdup("."); } char *expanded = ecex_path_expand_user(path); @@ -98,9 +92,7 @@ char *ecex_path_basename_dup(const char *path) { else if (slash && slash == path) base = "/"; else base = path; } - char *out = malloc(strlen(base) + 1); - if (out) strcpy(out, base); - return out; + return ecex_strdup(base); } char *ecex_path_normalize(const char *path) { -- cgit v1.2.3