From 98c7b03d739d2771cf67e73030968034a8c6ddac Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 25 Oct 2024 11:28:17 +0000 Subject: [PATCH] path: Move pakfire_path_is_absolute to the path library Signed-off-by: Michael Tremer --- src/libpakfire/include/pakfire/path.h | 2 ++ src/libpakfire/include/pakfire/util.h | 1 - src/libpakfire/path.c | 17 +++++++++++++++++ src/libpakfire/util.c | 9 --------- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/libpakfire/include/pakfire/path.h b/src/libpakfire/include/pakfire/path.h index 9059ddc7c..820b02c5c 100644 --- a/src/libpakfire/include/pakfire/path.h +++ b/src/libpakfire/include/pakfire/path.h @@ -47,6 +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); +int pakfire_path_is_absolute(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); diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 7bb432b7c..dbbb7306d 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -68,7 +68,6 @@ char* __pakfire_hexlify(const unsigned char* digest, const size_t length); #define pakfire_unhexlify(dst, src) __pakfire_unhexlify(dst, sizeof(dst), src) int __pakfire_unhexlify(unsigned char* dst, const size_t l, const char* src); -int pakfire_path_is_absolute(const char* path); const char* pakfire_path_relpath(const char* root, const char* path); #define pakfire_path_realpath(dest, path) \ diff --git a/src/libpakfire/path.c b/src/libpakfire/path.c index af8cd32ea..1bf0c0255 100644 --- a/src/libpakfire/path.c +++ b/src/libpakfire/path.c @@ -506,6 +506,23 @@ ERROR: return r; } +int pakfire_path_is_absolute(const char* s) { + struct pakfire_path* path = NULL; + int r; + + // Parse the path + r = pakfire_path_parse(&path, s); + if (r < 0) + return r; + + // Is this absolute? + r = path->is_absolute; + + pakfire_path_free(path); + + return r; +} + int __pakfire_path_absolute(char* buffer, const size_t length, const char* s) { struct pakfire_path* path = NULL; int r; diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index b8798036b..96a29aa75 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -58,15 +58,6 @@ #define BUFFER_SIZE 64 * 1024 #define NSEC_PER_SEC 1000000000 -int pakfire_path_is_absolute(const char* path) { - if (!path) { - errno = EINVAL; - return -1; - } - - return (*path == '/'); -} - const char* pakfire_path_relpath(const char* root, const char* path) { // Check inputs if (!root || !path) { -- 2.39.5