From: Karel Zak Date: Thu, 9 Apr 2026 08:39:52 +0000 (+0200) Subject: irqtop: use irqtop_puts() for pre-formatted table data X-Git-Url: http://git.ipfire.org/index.cgi?a=commitdiff_plain;h=72c00a41caea69968b39bcf220ff3a3c56e02a8c;p=thirdparty%2Futil-linux.git irqtop: use irqtop_puts() for pre-formatted table data 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 --- diff --git a/sys-utils/irqtop.c b/sys-utils/irqtop.c index c017053e7..eabd1ba6e 100644 --- a/sys-utils/irqtop.c +++ b/sys-utils/irqtop.c @@ -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 */