From: Michael Tremer Date: Sat, 11 Jan 2025 15:25:42 +0000 (+0000) Subject: path: Add function to format a path and normalize it straight away X-Git-Tag: 0.9.30~441 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4024128cc22610d5167d005a42aea16f478c4b96;p=pakfire.git path: Add function to format a path and normalize it straight away Signed-off-by: Michael Tremer --- diff --git a/src/pakfire/path.c b/src/pakfire/path.c index f90017a85..5c31b44ab 100644 --- a/src/pakfire/path.c +++ b/src/pakfire/path.c @@ -287,6 +287,22 @@ ERROR: return r; } +int __pakfire_path_format(char* buffer, const size_t length, const char* format, ...) { + va_list args; + int r; + + va_start(args, format); + r = __pakfire_string_vformat(buffer, length, format, args); + va_end(args); + + // Return any errors + if (r < 0) + return r; + + // Normalize the path + return __pakfire_path_normalize(buffer, length); +} + int __pakfire_path_append(char* buffer, const size_t length, const char* s1, const char* s2) { struct pakfire_path* path = NULL; int r; diff --git a/src/pakfire/path.h b/src/pakfire/path.h index b58e871a7..6ee180d3d 100644 --- a/src/pakfire/path.h +++ b/src/pakfire/path.h @@ -28,6 +28,10 @@ __pakfire_path_normalize(path, sizeof(path)) int __pakfire_path_normalize(char* p, const size_t length); +#define pakfire_path_format(path, format, ...) \ + __pakfire_path_format(path, sizeof(path), format, __VA_ARGS__) +int __pakfire_path_format(char* buffer, const size_t length, const char* format, ...); + #define pakfire_path_append(path, s1, s2) \ __pakfire_path_append(path, sizeof(path), s1, s2) int __pakfire_path_append(char* buffer, const size_t length, const char* s1, const char* s2);