From: Michael Tremer Date: Thu, 18 Aug 2022 15:51:28 +0000 (+0000) Subject: util: Refactor pakfire_path_join X-Git-Tag: 0.9.28~449 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56796f84677f154944e75bbc7215edaa557db7c6;p=pakfire.git util: Refactor pakfire_path_join Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/cgroup.c b/src/libpakfire/cgroup.c index 14062241a..957560e54 100644 --- a/src/libpakfire/cgroup.c +++ b/src/libpakfire/cgroup.c @@ -176,7 +176,7 @@ static int __pakfire_cgroup_create(struct pakfire_cgroup* cgroup) { // Compose the absolute path r = pakfire_path_join(path, ROOT, cgroup->path); - if (r < 0) + if (r) return 1; // Try creating the directory @@ -542,7 +542,7 @@ int pakfire_cgroup_child(struct pakfire_cgroup** child, // Join paths r = pakfire_path_join(path, cgroup->path, name); - if (r < 0) + if (r) return 1; // Open the child group diff --git a/src/libpakfire/compress.c b/src/libpakfire/compress.c index 0ed35fb4f..4d467147f 100644 --- a/src/libpakfire/compress.c +++ b/src/libpakfire/compress.c @@ -596,7 +596,7 @@ static int __pakfire_extract_entry(struct pakfire* pakfire, struct pakfire_extra if (*data->prefix) { // Compose file path r = pakfire_path_join(buffer, data->prefix, path); - if (r < 0) { + if (r) { ERROR(pakfire, "Could not compose file path: %m\n"); return r; } @@ -608,7 +608,7 @@ static int __pakfire_extract_entry(struct pakfire* pakfire, struct pakfire_extra const char* link = archive_entry_hardlink(entry); if (link) { r = pakfire_path_join(buffer, data->prefix, link); - if (r < 0) { + if (r) { ERROR(pakfire, "Could not compose hardlink path: %m\n"); return r; } diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 8150f085d..47a40adf9 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -51,9 +51,8 @@ char* __pakfire_hexlify(const unsigned char* digest, const size_t length); int __pakfire_unhexlify(unsigned char* dst, const size_t l, const char* src); #define pakfire_path_join(dest, first, second) \ - __pakfire_path_join(dest, sizeof(dest) - 1, first, second) - -int __pakfire_path_join(char* dest, size_t length, + __pakfire_path_join(dest, sizeof(dest), first, second) +int __pakfire_path_join(char* dest, const size_t length, const char* first, const char* second); const char* pakfire_path_relpath(const char* root, const char* path); diff --git a/src/libpakfire/jail.c b/src/libpakfire/jail.c index 3686c0a4d..1b3f23c2e 100644 --- a/src/libpakfire/jail.c +++ b/src/libpakfire/jail.c @@ -1504,7 +1504,7 @@ PAKFIRE_EXPORT int pakfire_jail_exec_script(struct pakfire_jail* jail, // Write the scriptlet to disk r = pakfire_path_join(path, root, "pakfire-script.XXXXXX"); - if (r < 0) + if (r) goto ERROR; // Open a temporary file diff --git a/src/libpakfire/mount.c b/src/libpakfire/mount.c index 025c41d16..b256a6759 100644 --- a/src/libpakfire/mount.c +++ b/src/libpakfire/mount.c @@ -344,7 +344,7 @@ int pakfire_mount_all(struct pakfire* pakfire) { for (const struct pakfire_mountpoint* mp = mountpoints; mp->source; mp++) { // Figure out where to mount r = pakfire_path_join(target, root, mp->target); - if (r < 0) + if (r) return r; // Create target diff --git a/src/libpakfire/repo.c b/src/libpakfire/repo.c index d0801a989..fe70a6e6f 100644 --- a/src/libpakfire/repo.c +++ b/src/libpakfire/repo.c @@ -1379,7 +1379,7 @@ PAKFIRE_EXPORT int pakfire_repo_compose(struct pakfire* pakfire, const char* pat // Make new path r = pakfire_path_join(destination_path, path, filename); - if (r < 0) + if (r) goto OUT; // Copying archive to destination diff --git a/src/libpakfire/util.c b/src/libpakfire/util.c index 436b31623..664fc24c5 100644 --- a/src/libpakfire/util.c +++ b/src/libpakfire/util.c @@ -71,19 +71,19 @@ char* pakfire_unquote_in_place(char* s) { return s; } -int __pakfire_path_join(char* dest, size_t length, +int __pakfire_path_join(char* dest, const size_t length, const char* first, const char* second) { if (!first) - return snprintf(dest, length, "%s", second); + return __pakfire_string_format(dest, length, "%s", second); if (!second) - return snprintf(dest, length, "%s", first); + return __pakfire_string_format(dest, length, "%s", first); // Remove leading slashes from second argument while (*second == '/') second++; - return snprintf(dest, length, "%s/%s", first, second); + return __pakfire_string_format(dest, length, "%s/%s", first, second); } const char* pakfire_path_relpath(const char* root, const char* path) {