From 8554541f3a6d9ba215580c38366d35cf5379460b Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 28 Jul 2025 22:18:52 +0100 Subject: [PATCH] io: path: add b_path_duplicate() --- io/include/blue/io/path.h | 3 ++- io/sys/darwin/path.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/io/include/blue/io/path.h b/io/include/blue/io/path.h index 2cae7d3..d33a03c 100644 --- a/io/include/blue/io/path.h +++ b/io/include/blue/io/path.h @@ -8,7 +8,7 @@ #define B_PATH(p) ((b_path *)p) -#define B_RV_PATH(cstr) B_RV(b_path_create_from_str(cstr)) +#define B_RV_PATH(cstr) B_PATH(B_RV(b_path_create_from_cstr(cstr))) struct b_file_info; @@ -18,6 +18,7 @@ BLUE_API b_path *b_path_create(); BLUE_API b_path *b_path_create_root(); BLUE_API b_path *b_path_create_cwd(); BLUE_API b_path *b_path_create_from_cstr(const char *path); +BLUE_API b_path *b_path_duplicate(const b_path *path); BLUE_API b_path *b_path_join(const b_path *paths[], size_t nr_paths); diff --git a/io/sys/darwin/path.c b/io/sys/darwin/path.c index 43c4048..47163bb 100644 --- a/io/sys/darwin/path.c +++ b/io/sys/darwin/path.c @@ -120,6 +120,22 @@ struct b_path *b_path_create_from_cstr(const char *cstr) return path; } +struct b_path *b_path_duplicate(const struct b_path *path) +{ + struct b_path *new_path = b_path_create(); + if (!path) { + return NULL; + } + + new_path->pathstr = b_string_duplicate(path->pathstr); + if (!new_path->pathstr) { + b_path_release(new_path); + return NULL; + } + + return new_path; +} + static void append_path(struct b_path *dest, const struct b_path *src) { if (b_path_is_absolute(src)) {