From e9be674fc3904dbc8be16578dab8d3c4bd97093a Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 25 Oct 2024 09:24:38 +0000 Subject: [PATCH] path: Add function to make a path absolute Signed-off-by: Michael Tremer --- src/libpakfire/include/pakfire/path.h | 4 ++++ src/libpakfire/path.c | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/libpakfire/include/pakfire/path.h b/src/libpakfire/include/pakfire/path.h index cb2d72a8d..9059ddc7c 100644 --- a/src/libpakfire/include/pakfire/path.h +++ b/src/libpakfire/include/pakfire/path.h @@ -47,4 +47,8 @@ int __pakfire_path_dirname(char* buffer, const size_t length, const char* s); __pakfire_path_relative(path, sizeof(path), root, s) int __pakfire_path_relative(char* buffer, const size_t length, const char* root, const char* s); +#define pakfire_path_absolute(path, s) \ + __pakfire_path_absolute(path, sizeof(path), s) +int __pakfire_path_absolute(char* buffer, const size_t length, const char* s); + #endif /* PAKFIRE_PATH_H */ diff --git a/src/libpakfire/path.c b/src/libpakfire/path.c index e18bf8d96..af8cd32ea 100644 --- a/src/libpakfire/path.c +++ b/src/libpakfire/path.c @@ -505,3 +505,27 @@ ERROR: return r; } + +int __pakfire_path_absolute(char* buffer, const size_t length, const char* s) { + struct pakfire_path* path = NULL; + int r; + + // Parse the path + r = pakfire_path_parse(&path, s); + if (r) + goto ERROR; + + // Make it absolute + path->is_absolute = 1; + + // Write back the path + r = pakfire_path_to_string(path, buffer, length); + if (r) + goto ERROR; + +ERROR: + if (path) + pakfire_path_free(path); + + return r; +} -- 2.39.5