From: Michael Tremer Date: Thu, 15 Apr 2021 17:17:33 +0000 (+0000) Subject: downloader: Use pakfire_string_* functions X-Git-Tag: 0.9.28~1285^2~358 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a7d38ba6a5785f874f763dd347027361e0089e30;p=pakfire.git downloader: Use pakfire_string_* functions Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/downloader.c b/src/libpakfire/downloader.c index dbfc8367a..01e1493b9 100644 --- a/src/libpakfire/downloader.c +++ b/src/libpakfire/downloader.c @@ -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", diff --git a/src/libpakfire/include/pakfire/util.h b/src/libpakfire/include/pakfire/util.h index 3655d81d2..2acd086fa 100644 --- a/src/libpakfire/include/pakfire/util.h +++ b/src/libpakfire/include/pakfire/util.h @@ -30,7 +30,8 @@ #include -#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);