From: Oliver Hartkopp Date: Mon, 5 May 2014 19:29:56 +0000 (+0200) Subject: candump: reduce printf calls for logfile format X-Git-Url: http://rtime.felk.cvut.cz/gitweb/can-utils.git/commitdiff_plain/31ccf45dc401ac80269bbaa6c0d1fe352e706006 candump: reduce printf calls for logfile format The creation of the logfile format was using fprint_canframe() and two other fprintf() calls to produce a single logfile format line. Instead of using fprint_canframe() use sprint_canframe() directly and reduce the printf() calls from three to one. Signed-off-by: Oliver Hartkopp --- diff --git a/candump.c b/candump.c index c865bd7..b67f3f8 100644 --- a/candump.c +++ b/candump.c @@ -698,18 +698,23 @@ int main(int argc, char **argv) view |= CANLIB_VIEW_INDENT_SFF; if (log) { + char buf[CL_CFSZ]; /* max length */ + /* log CAN frame with absolute timestamp & device */ - fprintf(logfile, "(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec); - fprintf(logfile, "%*s ", max_devname_len, devname[idx]); - /* without separator as logfile use-case is parsing */ - fprint_canframe(logfile, &frame, "\n", 0, maxdlen); + sprint_canframe(buf, &frame, 0, maxdlen); + fprintf(logfile, "(%010ld.%06ld) %*s %s\n", + tv.tv_sec, tv.tv_usec, + max_devname_len, devname[idx], buf); } if (logfrmt) { + char buf[CL_CFSZ]; /* max length */ + /* print CAN frame in log file style to stdout */ - printf("(%010ld.%06ld) ", tv.tv_sec, tv.tv_usec); - printf("%*s ", max_devname_len, devname[idx]); - fprint_canframe(stdout, &frame, "\n", 0, maxdlen); + sprint_canframe(buf, &frame, 0, maxdlen); + printf("(%010ld.%06ld) %*s %s\n", + tv.tv_sec, tv.tv_usec, + max_devname_len, devname[idx], buf); goto out_fflush; /* no other output to stdout */ }