]> git.ipfire.org Git - pakfire.git/commitdiff
path: Add function to make a path absolute
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 09:24:38 +0000 (09:24 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 25 Oct 2024 09:24:38 +0000 (09:24 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/include/pakfire/path.h
src/libpakfire/path.c

index cb2d72a8db213ccb25f76903bd8adf3061619606..9059ddc7c85175ba2431f8cb780cdc659d6df082 100644 (file)
@@ -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 */
index e18bf8d96e000635d3db3b21589777f2631e721e..af8cd32ea61e44c0a0b52ef55e8f2ca14cedccdb 100644 (file)
@@ -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;
+}