]> git.ipfire.org Git - pakfire.git/commitdiff
downloader: Use pakfire_string_* functions
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Apr 2021 17:17:33 +0000 (17:17 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 15 Apr 2021 17:17:33 +0000 (17:17 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/downloader.c
src/libpakfire/include/pakfire/util.h

index dbfc8367a6b4d33aa146bedbf1a964592340c973..01e1493b9007bd28d8f2c59f1c34f5af49baf49e 100644 (file)
@@ -261,13 +261,10 @@ static struct pakfire_transfer* pakfire_downloader_create_transfer(
                return NULL;
 
        // Copy URL
-       snprintf(transfer->url, sizeof(transfer->url) - 1, "%s", url);
+       pakfire_string_set(transfer->url, url);
 
        // Copy path
-       snprintf(transfer->path, sizeof(transfer->path) - 1, "%s", path);
-
-       // Make path for the temporary file (must be on the same file system)
-       snprintf(transfer->tempfile, sizeof(transfer->tempfile) - 1, "%s.XXXXXX", path);
+       pakfire_string_set(transfer->path, path);
 
        // Keep a reference to the mirrorlist
        if (mirrors)
@@ -520,6 +517,11 @@ static int pakfire_downloader_prepare_transfer(struct pakfire_downloader* downlo
 
        // Open a temporary file to write the output to
        if (!transfer->f) {
+               // Make path for the temporary file (must be on the same file system)
+               int r = pakfire_string_format(transfer->tempfile, "%s.XXXXXX", transfer->path);
+               if (r < 0)
+                       return 1;
+
                transfer->f = pakfire_mktemp(transfer->tempfile);
                if (!transfer->f) {
                        ERROR(downloader->pakfire, "Could not create temporary file for download %s: %s\n",
index 3655d81d2f5bdd62f04da78ec27bd12c700e67f1..2acd086fa0b215390d74091c27131598ed170e32 100644 (file)
@@ -30,7 +30,8 @@
 
 #include <pakfire/types.h>
 
-#define pakfire_string_set(s, value) snprintf(s, sizeof(s) - 1, "%s", value)
+#define pakfire_string_format(s, fmt, ...) snprintf(s, sizeof(s) - 1, fmt, __VA_ARGS__)
+#define pakfire_string_set(s, value) pakfire_string_format(s, "%s", value)
 
 int pakfire_string_startswith(const char* s, const char* prefix);
 int pakfire_string_endswith(const char* s, const char* suffix);