]> git.ipfire.org Git - pakfire.git/commitdiff
pakfire: Remove path and cache_path into struct
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Mar 2021 19:26:47 +0000 (19:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 10 Mar 2021 19:26:47 +0000 (19:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/pakfire.c

index 6d5c5d4d282b67708463a98e5e9e8181b732f623..d56144bb0209297e4fb1d509ff390f0cd6e5d296 100644 (file)
@@ -52,8 +52,8 @@
 #include <pakfire/util.h>
 
 struct _Pakfire {
-       char* path;
-       char* cache_path;
+       char path[PATH_MAX];
+       char cache_path[PATH_MAX];
        char* arch;
 
        // Pool stuff
@@ -146,12 +146,6 @@ static void pakfire_free(Pakfire pakfire) {
        if (pakfire->arch)
                free(pakfire->arch);
 
-       if (pakfire->path)
-               free(pakfire->path);
-
-       if (pakfire->cache_path)
-               free(pakfire->cache_path);
-
        free(pakfire);
 }
 
@@ -183,7 +177,8 @@ PAKFIRE_EXPORT int pakfire_create(Pakfire* pakfire, const char* path, const char
 
        p->nrefs = 1;
 
-       p->path = strdup(path);
+       // Set path
+       snprintf(p->path, sizeof(p->path) - 1, "%s", path);
 
        // Set architecture
        p->arch = strdup(arch);
@@ -249,7 +244,7 @@ PAKFIRE_EXPORT const char* pakfire_get_path(Pakfire pakfire) {
 
 PAKFIRE_EXPORT char* pakfire_make_path(Pakfire pakfire, const char* path) {
        // Make sure that path never starts with /
-       if (path && path[0] == '/')
+       while (path && *path == '/')
                path++;
 
        return pakfire_path_join(pakfire->path, path);
@@ -665,13 +660,9 @@ PAKFIRE_EXPORT const char* pakfire_get_cache_path(Pakfire pakfire) {
 }
 
 PAKFIRE_EXPORT void pakfire_set_cache_path(Pakfire pakfire, const char* path) {
-       // Release old path
-       if (pakfire->cache_path)
-               free(pakfire->cache_path);
-
-       pakfire->cache_path = strdup(path);
+       DEBUG(pakfire, "Setting cache path to %s\n", path);
 
-       DEBUG(pakfire, "Set cache path to %s\n", pakfire->cache_path);
+       snprintf(pakfire->cache_path, sizeof(pakfire->cache_path) - 1, "%s", path);
 }
 
 PAKFIRE_EXPORT char* pakfire_make_cache_path(Pakfire pakfire, const char* path) {