]> git.ipfire.org Git - pakfire.git/commitdiff
progressbar: Use pakfire_string_* functions
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Apr 2021 13:08:23 +0000 (13:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 20 Apr 2021 13:08:23 +0000 (13:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/progressbar.c

index 22d70a3c147c4430dd0947c50559d6a767dfe25f..c0e299c29f01fbebde88bba64afa12bb9a3ff356 100644 (file)
@@ -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;
        }