From: Michael Tremer Date: Wed, 10 Mar 2021 19:26:47 +0000 (+0000) Subject: pakfire: Remove path and cache_path into struct X-Git-Tag: 0.9.28~1285^2~574 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee6fbbeb68fcfc7b2f63bbc9b4a41e985156a89e;p=pakfire.git pakfire: Remove path and cache_path into struct Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/pakfire.c b/src/libpakfire/pakfire.c index 6d5c5d4d2..d56144bb0 100644 --- a/src/libpakfire/pakfire.c +++ b/src/libpakfire/pakfire.c @@ -52,8 +52,8 @@ #include 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) {