]> git.ipfire.org Git - pakfire.git/commitdiff
util: Refactor pakfire_path_join
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Aug 2022 15:51:28 +0000 (15:51 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 18 Aug 2022 15:51:28 +0000 (15:51 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/cgroup.c
src/libpakfire/compress.c
src/libpakfire/include/pakfire/util.h
src/libpakfire/jail.c
src/libpakfire/mount.c
src/libpakfire/repo.c
src/libpakfire/util.c

index 14062241a4148105fee4ca176cda8f9d9437c1ba..957560e54d8b325f14660eae05cda0fd0706cad3 100644 (file)
@@ -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
index 0ed35fb4f509bbf1534802c7b79873059926df37..4d467147fe41f8ab7afafa937469d4127b9dfe06 100644 (file)
@@ -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;
                        }
index 8150f085d5f0c4a89181102778f8511f5427f4af..47a40adf9ee9b791ea7355a0b33f720001765793 100644 (file)
@@ -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);
 
index 3686c0a4df127843348ee33827e38f59b3c272d3..1b3f23c2ed67159d071a3983344f6888a767807f 100644 (file)
@@ -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
index 025c41d160ca30994e642d43154f348d253141c9..b256a6759eef52c851d33450c7ac4855f91a7922 100644 (file)
@@ -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
index d0801a989f1b7715057dcecd02e07e1717c35ffb..fe70a6e6f34902ac41d75601f2058f697faca058 100644 (file)
@@ -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
index 436b31623aaec7c9b1c135ba03fa181b0aac2ef4..664fc24c5e29c2da47ab0644e1a0d27b9a8f837f 100644 (file)
@@ -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) {