From: Michael Tremer Date: Tue, 20 Apr 2021 13:08:23 +0000 (+0000) Subject: progressbar: Use pakfire_string_* functions X-Git-Tag: 0.9.28~1285^2~295 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b8ebd5b5fd3726d1c4b250c98f1d4a235835abe;p=pakfire.git progressbar: Use pakfire_string_* functions Signed-off-by: Michael Tremer --- diff --git a/src/libpakfire/progressbar.c b/src/libpakfire/progressbar.c index 22d70a3c1..c0e299c29 100644 --- a/src/libpakfire/progressbar.c +++ b/src/libpakfire/progressbar.c @@ -433,7 +433,7 @@ int pakfire_progressbar_add_string(struct pakfire_progressbar* p, const char* fo static const char* pakfire_progressbar_counter(struct pakfire_progressbar* p, struct pakfire_progressbar_widget* widget, unsigned int width, void* data) { - int r = snprintf(widget->buffer, sizeof(widget->buffer), "%lu/%lu", p->value, p->value_max); + int r = pakfire_string_format(widget->buffer, "%lu/%lu", p->value, p->value_max); if (r < 0) return NULL; @@ -450,7 +450,7 @@ static const char* pakfire_progressbar_percentage(struct pakfire_progressbar* p, struct pakfire_progressbar_widget* widget, unsigned int width, void* data) { double percentage = p->value * 100.0 / p->value_max; - int r = snprintf(widget->buffer, sizeof(widget->buffer), "%3.0f%%", percentage); + int r = pakfire_string_format(widget->buffer, "%3.0f%%", percentage); if (r < 0) return NULL; @@ -500,7 +500,7 @@ static const char* pakfire_progressbar_timer(struct pakfire_progressbar* p, if (t < 0) return NULL; - int r = snprintf(widget->buffer, sizeof(widget->buffer), "%02lu:%02lu", t / 60, t % 60); + int r = pakfire_string_format(widget->buffer, "%02lu:%02lu", t / 60, t % 60); if (r < 0) return NULL; @@ -527,14 +527,14 @@ static const char* pakfire_progressbar_eta(struct pakfire_progressbar* p, // Print a placeholder when we haven't started yet if (p->value == 0) { - r = snprintf(widget->buffer, sizeof(widget->buffer) - 1, "%-5s: --:--:--", _("ETA")); + r = pakfire_string_format(widget->buffer, "%-5s: --:--:--", _("ETA")); if (r < 0) return NULL; // Show total time when finished } else if (p->status == PAKFIRE_PROGRESSBAR_FINISHED) { - r = snprintf(widget->buffer, sizeof(widget->buffer) - 1, - "%-5s: %02lu:%02lu", _("Time"), t / 60, t % 60); + r = pakfire_string_format(widget->buffer, "%-5s: %02lu:%02lu", + _("Time"), t / 60, t % 60); if (r < 0) return NULL; @@ -542,8 +542,8 @@ static const char* pakfire_progressbar_eta(struct pakfire_progressbar* p, } else { time_t eta = t * p->value_max / p->value - t; - r = snprintf(widget->buffer, sizeof(widget->buffer) - 1, - "%-5s: %02lu:%02lu", _("ETA"), eta / 60, eta % 60); + r = pakfire_string_format(widget->buffer, "%-5s: %02lu:%02lu", + _("ETA"), eta / 60, eta % 60); if (r < 0) return NULL; }