aboutsummaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
authorDavid Moc <personal@cdatgoose.org>2026-06-03 02:26:11 +0200
committerDavid Moc <personal@cdatgoose.org>2026-06-03 02:26:11 +0200
commitc6d44836fd8ed1442e01825cb0f9f97e7bf11515 (patch)
treed0e8cededdecafdf27476a744ac2d892d5a18620 /src/path.c
parentb68766967c86a6a789d65772f69f7f44939ebdf2 (diff)
Harden editor logging and packaging
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c22
1 files changed, 7 insertions, 15 deletions
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 <ctype.h>
#include <stdio.h>
#include <stdlib.h>
@@ -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) {