From: Michael Tremer Date: Fri, 25 Oct 2024 09:24:38 +0000 (+0000) Subject: path: Add function to make a path absolute X-Git-Tag: 0.9.30~907 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e9be674fc3904dbc8be16578dab8d3c4bd97093a;p=pakfire.git path: Add function to make a path absolute Signed-off-by: Michael Tremer --- 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; +}