]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
irqtop: use irqtop_puts() for pre-formatted table data
authorKarel Zak <kzak@redhat.com>
Thu, 9 Apr 2026 08:39:52 +0000 (10:39 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 9 Apr 2026 08:39:52 +0000 (10:39 +0200)
Avoid unnecessary printf formatting when outputting pre-formatted
table strings. The new irqtop_puts() writes data directly via
fputs/waddstr without extra buffer allocation, appending a specified
number of trailing newlines.

This also reduces the buffer size requirements for the vw_printw()
slang fallback, which is now only used for the short header line.

Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/irqtop.c

index c017053e7e32dd7c1020e63d209aecc63cd9707b..eabd1ba6eb2c9620b541a36fc3ec1b6887f1fa73 100644 (file)
@@ -101,6 +101,22 @@ static inline int vw_printw(WINDOW *win, const char *fmt, va_list args)
 }
 #endif
 
+/* Write pre-formatted data to the screen, followed by @nl newlines */
+static inline void irqtop_puts(struct irqtop_ctl *ctl, const char *data, int nl)
+{
+       if (ctl->batch) {
+               fputs(data, stdout);
+               while (nl--)
+                       fputc('\n', stdout);
+       } else {
+               waddstr(ctl->win, (char *) data);
+               while (nl--)
+                       waddch(ctl->win, '\n');
+               wrefresh(ctl->win);
+       }
+}
+
+/* Write formatted output to the screen */
 static inline int irqtop_printf(struct irqtop_ctl *ctl, const char *fmt, ...)
 {
        int ret = 0;
@@ -184,7 +200,7 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
        if (cpus) {
                scols_print_table_to_string(cpus, &data);
                if (data && *data)
-                       irqtop_printf(ctl, "%s\n\n", data);
+                       irqtop_puts(ctl, data, 2);
                free(data);
        }
 
@@ -199,14 +215,14 @@ static int update_screen(struct irqtop_ctl *ctl, struct irq_output *out)
                *p = '\0';
                if (!ctl->batch)
                        attron(A_REVERSE);
-               irqtop_printf(ctl, "%s\n", data);
+               irqtop_puts(ctl, data, 1);
                if (!ctl->batch)
                        attroff(A_REVERSE);
                data = p + 1;
        }
 
        if (data && *data)
-               irqtop_printf(ctl, "%s\n\n", data);
+               irqtop_puts(ctl, data, 2);
        free(data0);
 
        /* clean up */